前提・実現したいこと
Bクラスでファイルから値を求めて座標化し、そこからx座標、y座標の最小値、最大値を求めたのですがその値をSクラスでも使用したいです。
発生している問題・エラーメッセージ
該当のソースコード
python
1コード 2 3import cv2 4import numpy as np 5import scipy.misc as scm 6import matplotlib.pyplot as plt 7from PIL import Image 8 9 10 11class AAA: 12 def __init__(self,a,b): 13 self.a = a 14 self.b = b 15 self.c = np.array(0) 16 def sample1(self,filename): 17 f = open(filename) 18 self.b = f.readline() 19 self.a = str(f.readline()) 20 self.d = int(f.readline()) 21 self.c = [] 22 for i in range(self.d): 23 self.c.append(Stroke()) 24 self.c[i].loadStroke(f) 25 return self.c 26 f.close() 27 28 def prin(self): 29 plt.show() 30 31 32 33 def d(self): 34 return self.d 35 36 37class St: 38 def __init__(self): 39 self.e = np.array(2) 40 41 42 43 def load(self,file): 44 self.g = int(file.readline()) 45 self.e = [] 46 for i in range(self.g): 47 self.e.append(Path()) 48 self.e[i].loadPath(file) 49 50 def getP(self): 51 self.get_xmin() 52 self.get_ymin() 53 self.get_xmax() 54 self.get_ymax() 55 56 57 def get_xmin(self): 58 min_xpath_list = [] 59 for i in range(self.g): 60 min_xpath_list.append(self.e[i].get_xmin()) 61 cal_min_xpath_list = np.array(min_xpath_list) 62 self.truexmin = cal_min_xpath_list.min() 63 64 65 def get_ymin(self): 66 min_ypath_list = [] 67 for i in range(self.g): 68 min_ypath_list.append(self.e[i].get_ymin()) 69 cal_min_ypath_list = np.array(min_ypath_list) 70 self.trueymin = cal_min_ypath_list.min() 71 72 73 def get_xmax(self): 74 max_xpath_list = [] 75 for i in range(self.g): 76 max_xpath_list.append(self.e[i].get_xmax()) 77 print(max_xpath_list) 78 cal_max_xpath_list = np.array(max_xpath_list) 79 self.truexmax = cal_max_xpath_list.max() 80 print(self.truexmax) 81 print("ccc") 82 83 def get_ymax(self): 84 max_ypath_list = [] 85 for i in range(self.g): 86 max_ypath_list.append(self.e[i].get_ymax()) 87 print(max_ypath_list) 88 cal_max_ypath_list = np.array(max_ypath_list) 89 self.trueymax = cal_max_ypath_list.max() 90 print(self.trueymax) 91 print("ddd") 92 93 94 95 96 97 98class B: 99 def __init__(self): 100 self.TA_x = 0 101 self.TA_y = 0 102 self.TB_x = 0 103 self.TB_y = 0 104 self.CA_x = 0 105 self.CA_y = 0 106 self.CB_x = 0 107 self.CB_y = 0 108 self.P = [] 109 110 def loadP(self,file): 111 buf = file.readline() 112 str = buf.split(",") 113 self.TA_x = float(str[0]) 114 self.TA_y = float(str[1]) 115 self.TB_x = float(str[2]) 116 self.TB_y = float(str[3]) 117 self.CA_x = float(str[4]) 118 self.CA_y = float(str[5]) 119 self.CB_x = float(str[6]) 120 self.CB_y = float(str[7]) 121 self.q = np.array([[self.TA_x, self.TA_y], [self.TB_x, self.TB_y], 122 [self.CA_x, self.CA_y], [self.CB_x, self.CB_y]], dtype=np.float) 123 self.xarray = np.array([[self.TA_x],[self.CB_x]],dtype = np.float) 124 self.yarray = np.array([[self.TA_y],[self.CB_y]],dtype = np.float) 125 self.sampling() 126 self.get_xmin() 127 self.get_ymin() 128 self.get_xmax() 129 self.get_ymax() 130 131 132 133 def bernstein(self,n, i, t): 134 return scm.comb(n, i) * t**i * (1 - t)**(n-i) 135 136 def bezier(self,n, t, q): 137 p = np.zeros(2) 138 for i in range(n + 1): 139 p += self.bernstein(n, i, t) * q[i] 140 return p 141 142 143 def sampling(self): 144 for t in np.linspace(0, 1, 50): 145 self.P.append(self.bezier(3, t, self.q)) 146 self.p = np.array(self.P) 147 plt.plot(self.p.T[0],self.p.T[1],marker=".") 148 149 150 def get_xmin(self): 151 self.xmin = self.xarray.min() 152 return self.xmin 153 154 155 def get_ymin(self): 156 self.ymin = self.yarray.min() 157 return self.ymin 158 159 def get_xmax(self): 160 self.xmax = self.xarray.max() 161 return self.xmax 162 163 def get_ymax(self): 164 self.ymax = self.yarray.max() 165 return self.ymax 166 167 168 169class S: 170 def __init__(self,input,mojimodel,loopMax=2000): 171 self.loopMax = loopMax 172 self.input = input 173 174 175 def changeP(self): 176 ここに前のクラスでファイルから読み込んだ値の中で求めた座標の最小値、最大値を使用したい
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/15 10:51