@@ -87,6 +87,8 @@ def triang_3D(col_1, row_1, col_2, row_2) :
87
87
x = M1 [0 ]/ M1 [3 ]
88
88
y = M1 [1 ]/ M1 [3 ]
89
89
z = M1 [2 ]/ M1 [3 ]
90
+ v1L = np .array ([x0 , y0 , z0 ])
91
+ v2L = np .array ([x , y , z ])
90
92
a = x - x0
91
93
b = y - y0
92
94
c = z - z0
@@ -103,6 +105,8 @@ def triang_3D(col_1, row_1, col_2, row_2) :
103
105
x = M2 [0 ]/ M2 [3 ]
104
106
y = M2 [1 ]/ M2 [3 ]
105
107
z = M2 [2 ]/ M2 [3 ]
108
+ v1R = np .array ([x1 , y1 , z1 ])
109
+ v2R = np .array ([x , y , z ])
106
110
d = x - x1
107
111
e = y - y1
108
112
f = z - z1
@@ -120,8 +124,26 @@ def triang_3D(col_1, row_1, col_2, row_2) :
120
124
x_coord = x0 + a * r [0 ]
121
125
y_coord = y0 + b * r [0 ]
122
126
z_coord = z0 + c * r [0 ]
127
+ M = np .array ([x_coord , y_coord , z_coord ])
123
128
124
- return (x_coord [0 ], y_coord [0 ], z_coord [0 ])
129
+ #compute distance to each ray from the estimated 3D location
130
+ v1L = v1L .transpose ()
131
+ v2L = v2L .transpose ()
132
+ v1R = v1R .transpose ()
133
+ v2R = v2R .transpose ()
134
+
135
+ d1 = LA .norm (np .cross (np .subtract (v1L , v2L ),np .subtract (M .transpose (),v2L )))/ LA .norm (np .subtract (v1L ,v2L ))
136
+ d2 = LA .norm (np .cross (np .subtract (v1R , v2R ),np .subtract (M .transpose (),v2R )))/ LA .norm (np .subtract (v1R ,v2R ))
137
+ err1 = d1 + d2 ;
138
+
139
+ #project the estimated 3D position onto image, then find distance from original position
140
+ m1rn = np .dot (P1 ,np .vstack ((M ,[1 ])))
141
+ m2rn = np .dot (P2 ,np .vstack ((M ,[1 ])))
142
+ m1r = m1rn / m1rn [2 ]
143
+ m2r = m2rn / m2rn [2 ]
144
+ err2 = np .sqrt (np .sum (np .square (m1r [0 :2 ]- m1 [0 :2 ]))) + np .sqrt (np .sum (np .square (m2r [0 :2 ]- m2 [0 :2 ])))
145
+
146
+ return (x_coord [0 ], y_coord [0 ], z_coord [0 ], err1 , err2 )
125
147
126
148
#---------------------------------------------------------
127
149
def getthresholdedimg (im ):
@@ -188,7 +210,7 @@ def procImg(img,sideName):
188
210
pt2 = (bound_rect [0 ] + bound_rect [2 ], bound_rect [1 ] + bound_rect [3 ])
189
211
190
212
# Draw bounding rectangle
191
- cv .Rectangle (img , pt1 , pt2 , cv .CV_RGB (255 ,0 ,0 ), 1 )
213
+ cv .Rectangle (img , pt1 , pt2 , cv .CV_RGB (255 ,0 ,0 ), 3 )
192
214
193
215
# calculating centroid
194
216
centroidx = cv .Round ((pt1 [0 ]+ pt2 [0 ])/ 2 )
@@ -217,16 +239,16 @@ def procImg(img,sideName):
217
239
url_west = 'http://10.129.20.12/snapshot/view0.jpg'
218
240
219
241
# three windows that will open upon execution
220
- cv .NamedWindow ("west" ,cv .CV_WINDOW_NORMAL )
221
- cv .NamedWindow ("east" ,cv .CV_WINDOW_NORMAL )
242
+ cv .NamedWindow ("west" ,cv .CV_WINDOW_AUTOSIZE )
243
+ cv .NamedWindow ("east" ,cv .CV_WINDOW_AUTOSIZE )
222
244
223
245
#address of the control server
224
246
ip = "md-red5.discovery.wisc.edu"
225
247
port = 7779
226
248
size = 1024
227
249
228
250
#first get a connection to the server
229
- s = connect (ip ,port )
251
+ # s = connect(ip,port)
230
252
231
253
232
254
while (1 ):
@@ -251,10 +273,17 @@ def procImg(img,sideName):
251
273
centx_east = centroids [0 ]
252
274
centy_east = centroids [1 ]
253
275
276
+ #decimate the resulting images
277
+ small_west = cv .CreateImage ((int (0.5 * cv .GetSize (frame_west )[0 ]), int (0.5 * cv .GetSize (frame_west )[1 ])), 8 , 3 )
278
+ small_east = cv .CreateImage ((int (0.5 * cv .GetSize (frame_east )[0 ]), int (0.5 * cv .GetSize (frame_east )[1 ])), 8 , 3 )
279
+ cv .Resize (frame_west , small_west )
280
+ cv .Resize (frame_east , small_east )
281
+
282
+
254
283
#display the images with the blimp outlined
255
- cv .ShowImage ("west" , frame_west )
284
+ cv .ShowImage ("west" , small_west )
256
285
cv .WaitKey (100 )
257
- cv .ShowImage ("east" , frame_east )
286
+ cv .ShowImage ("east" , small_east )
258
287
cv .WaitKey (100 )
259
288
260
289
#get the 3D location of the blimp
@@ -263,18 +292,20 @@ def procImg(img,sideName):
263
292
print ("x_3d: " + str (coord3D [0 ]))
264
293
print ("y_3d: " + str (coord3D [1 ]))
265
294
print ("z_3d: " + str (coord3D [2 ]))
295
+ print ("err1: " + str (coord3D [3 ]))
296
+ print ("err2: " + str (coord3D [4 ]))
266
297
print ("-----------------------------------" )
267
298
268
- #send the 3D location to the control server
269
- try :
270
- #x,y,z = getPosition()
271
- msg = "" + str (coord3D [0 ]) + "," + str (coord3D [1 ]) + "," + str (coord3D [2 ]) + "\n "
272
- s .send (msg )
273
- #time.sleep(1)
274
- except Exception as err :
275
- print ("disconnected" )
276
- #we got disconnected somehow, reconnect
277
- s = connect (ip ,port )
299
+ ## #send the 3D location to the control server
300
+ ## try:
301
+ ## #x,y,z = getPosition()
302
+ ## msg = "" + str(coord3D[0]) + "," + str(coord3D[1]) + "," + str(coord3D[2]) + "\n"
303
+ ## s.send(msg)
304
+ ## #time.sleep(1)
305
+ ## except Exception as err:
306
+ ## print("disconnected")
307
+ ## #we got disconnected somehow, reconnect
308
+ ## s = connect(ip,port)
278
309
279
310
280
311
0 commit comments