質問編集履歴
1
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
グラフ表示をする。。。
|
test
CHANGED
@@ -44,253 +44,7 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
windowName_3 = u'result'.encode('cp932')
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
cv2.namedWindow(windowName_3)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
img_obj = cv2.imread('brack.jpg', cv2.IMREAD_COLOR)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if img_obj is None:
|
62
|
-
|
63
|
-
print u'画像が取得できません。'
|
64
|
-
|
65
|
-
sys.exit()
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
src = cv2.VideoCapture('yellow.avi')
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if not src.isOpened():
|
74
|
-
|
75
|
-
print u'映像が取得できません。'
|
76
|
-
|
77
|
-
sys.exit()
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
retval, frame = src.read()
|
82
|
-
|
83
|
-
height1, width1, channels1 = img_obj.shape
|
84
|
-
|
85
|
-
height2, width2, channels2 = frame.shape
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
rec = cv2.VideoWriter('blue.avi', cv.CV_FOURCC('X','V','I','D'), 6, (width2, height2))
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
f = open('0deg result.csv', 'ab')
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
d2=('0deg result.csv')
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
csvWriter = csv.writer(f)
|
102
|
-
|
103
|
-
val = 0
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
while True:
|
108
|
-
|
109
|
-
retval, frame = src.read()
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if frame is None:
|
114
|
-
|
115
|
-
break
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
# テンプレート・マッチングにより相互相関係数を計算
|
126
|
-
|
127
|
-
img_ccoeff1 = cv2.matchTemplate(frame, img_obj, cv2.TM_CCOEFF_NORMED)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
# [-1, 1] を [0, 1] へ
|
132
|
-
|
133
|
-
cv2.normalize(img_ccoeff1,img_ccoeff1, 0, 1, cv2.NORM_MINMAX)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# 相互相関係数の最小値・最大値とその座標を抽出
|
138
|
-
|
139
|
-
cMin, cMax, pMin, pMax1 = cv2.minMaxLoc(img_ccoeff1)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
# 検出領域の中心座標
|
144
|
-
|
145
|
-
detect = (pMax1[0] + width1/2, pMax1[1] + height1/2)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
x = pMax1[0] + width1/2, pMax1[1] + height1/2
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
x1 = (((round(((pMax1[0] + width1/2)-385)*0.327,2))), (round(((pMax1[1] + height1/2)-290)*0.327,2)))
|
156
|
-
|
157
|
-
x2 = (round(((pMax1[0] + width1/2)-385)*0.327,2))
|
158
|
-
|
159
|
-
y2 = (round(((pMax1[1] + height1/2)-290)*0.327,2))
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
a = np.array([x2,y2])
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
# 探索画像から検出領域を抽出
|
172
|
-
|
173
|
-
img_crop = frame[pMax1[1]:pMax1[1]+height1, pMax1[0]:pMax1[0]+width1].copy()
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
# 検出領域に赤色の円と十字を描画
|
178
|
-
|
179
|
-
cv2.circle(frame, detect, width1/2, (0, 0, 255), 1)
|
180
|
-
|
181
|
-
cv2.line(frame,((pMax1[0] + width1/2) - 25, pMax1[1] + height1/2), ((pMax1[0] + width1/2) + 25 , pMax1[1] + height1/2), (0, 0, 255), 1)
|
182
|
-
|
183
|
-
cv2.line(frame,((pMax1[0] + width1/2), (pMax1[1] + height1/2 )-25), ((pMax1[0] + width1/2), (pMax1[1] + height1/2) + 25), (0, 0, 255), 1)
|
184
|
-
|
185
|
-
# テンプレート・マッチングにより相互相関係数を計算
|
186
|
-
|
187
|
-
img_ccoeff2 = cv2.matchTemplate(frame, img_obj, cv2.TM_CCOEFF_NORMED)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
# [-1, 1] を [0, 1] へ
|
192
|
-
|
193
|
-
cv2.normalize(img_ccoeff2,img_ccoeff2, 0, 1, cv2.NORM_MINMAX)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
# 相互相関係数の最小値・最大値とその座標を抽出
|
198
|
-
|
199
|
-
cMin, cMax, pMin, pMax2 = cv2.minMaxLoc(img_ccoeff2)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
# 検出領域の中心座標
|
204
|
-
|
205
|
-
detect = (pMax2[0] + width1/2, pMax2[1] + height1/2)
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
y = pMax2[0] + width1/2, pMax2[1] + height1/2
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
y1 = (round(((pMax2[0] + width1/2)-385)*0.327,2), round(((pMax2[1] + height1/2)-290)*0.327,2))
|
216
|
-
|
217
|
-
x3 = (round(((pMax2[0] + width1/2)-385)*0.327,2))
|
218
|
-
|
219
|
-
y3 = (round(((pMax2[1] + height1/2)-290)*0.327,2))
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
b = np.array([x3, y3])
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
l = np.linalg.norm(b-a)
|
228
|
-
|
229
|
-
l = (round(l,2))
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
L = (round((x2+x3)/2,2), round((y2+y3)/2,2))
|
236
|
-
|
237
|
-
LX =round((x2+x3)/2,2)
|
238
|
-
|
239
|
-
LY =round((y2+y3)/2,2)
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
# 探索画像から検出領域を抽出
|
248
|
-
|
249
|
-
img_crop = frame[pMax2[1]:pMax2[1]+height1, pMax2[0]:pMax2[0]+width1].copy()
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
# 検出領域に赤色の円と十字を描画
|
254
|
-
|
255
|
-
cv2.circle(frame, detect, width1/2, (0, 0, 255), 1)
|
256
|
-
|
257
|
-
cv2.line(frame,((pMax2[0] + width1/2) - 25, pMax2[1] + height1/2), ((pMax2[0] + width1/2) + 25 , pMax2[1] + height1/2), (0, 0, 255), 1)
|
258
|
-
|
259
|
-
cv2.line(frame,((pMax2[0] + width1/2), (pMax2[1] + height1/2 )-25), ((pMax2[0] + width1/2), (pMax2[1] + height1/2) + 25), (0, 0, 255), 1)
|
260
|
-
|
261
|
-
#cv2.line(frame, (pMax[0] + width/2, pMax[1] + height/2), (pMax[0] + width/2,(pMax[1] + height)/3), (0, 0, 255), 1)
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
cv2.imshow(windowName_3, frame)
|
268
|
-
|
269
|
-
rec.write(frame)
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
#list = (str(time),str(x) )
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
csvWriter.writerow([str(time)]+[str(x2)]+[str(y2)]+[str(x3)]+[str(y3)]+[str(LX)]+[str(LY)]+[str(l)]+[str(X)]+[str(Y)]+[str(Z)])
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
key = cv2.waitKey(33) # キー入力待機(33 ms)
|
284
|
-
|
285
|
-
if key == 27: # ESCキーを押したとき終了
|
286
|
-
|
287
|
-
break
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
# データ読み込み
|
292
|
-
|
293
|
-
d1 = genfromtxt("P
|
47
|
+
d1 = genfromtxt("P.csv", delimiter=",")
|
294
48
|
|
295
49
|
|
296
50
|
|