10
10
import time
11
11
12
12
global imghsv
13
- global x_3d , y_3d , z_3d
14
13
15
14
# purpose: using HSV thresholds, detects blue, yellow and purple objects in a video stream in three new windows
16
15
# 1) a black/white stream showing objects matching threshold values (window "threshold")
@@ -35,6 +34,7 @@ def connect(ip,port):
35
34
s .settimeout (1 )
36
35
#keep trying to connect to the server until success
37
36
print ("connecting to control server..." )
37
+ print ("" )
38
38
connected = False
39
39
#while not connected:
40
40
try :
@@ -51,7 +51,7 @@ def connect(ip,port):
51
51
#These constants are produced by matlab code that is available here:
52
52
#http://www.vision.caltech.edu/bouguetj/calib_doc/
53
53
def triang_3D (col_1 , row_1 , col_2 , row_2 ) :
54
- global x_3d , y_3d , z_3d
54
+
55
55
#R matrix for camera 1 (west side)
56
56
R1 = np .array ([[- 74.2709 , 637.41 , - 255.7461 ], [865.2027 , 273.6518 , - 92.0415 ], [0.1602 , 0.3172 , - 0.9347 ]])
57
57
#T matrix for camera 1
@@ -121,9 +121,7 @@ def triang_3D(col_1, row_1, col_2, row_2) :
121
121
y_coord = y0 + b * r [0 ]
122
122
z_coord = z0 + c * r [0 ]
123
123
124
- x_3d = x_coord
125
- y_3d = y_coord
126
- z_3d = z_coord
124
+ return (x_coord [0 ], y_coord [0 ], z_coord [0 ])
127
125
128
126
#---------------------------------------------------------
129
127
def getthresholdedimg (im ):
@@ -160,10 +158,12 @@ def procImg(img,sideName):
160
158
161
159
#creates empty images of the same size
162
160
imdraw = cv .CreateImage (cv .GetSize (img ), 8 , 3 )
161
+ #put the smoothed image here
162
+ imgSmooth = cv .CreateImage (cv .GetSize (img ), 8 , 3 )
163
163
164
164
cv .SetZero (imdraw )
165
- cv .Smooth (img , img , cv .CV_GAUSSIAN , 3 , 0 )
166
- imgbluethresh = getthresholdedimg (img )
165
+ cv .Smooth (img , imgSmooth , cv .CV_GAUSSIAN , 3 , 0 ) #Gaussian filter the image
166
+ imgbluethresh = getthresholdedimg (imgSmooth ) #Get a color thresholed binary image
167
167
cv .Erode (imgbluethresh , imgbluethresh , None , 3 )
168
168
cv .Dilate (imgbluethresh , imgbluethresh , None , 10 )
169
169
img2 = cv .CloneImage (imgbluethresh )
@@ -217,16 +217,16 @@ def procImg(img,sideName):
217
217
url_west = 'http://10.129.20.12/snapshot/view0.jpg'
218
218
219
219
# three windows that will open upon execution
220
- cv .NamedWindow ("west" ,cv .CV_WINDOW_AUTOSIZE )
221
- cv .NamedWindow ("east" ,cv .CV_WINDOW_AUTOSIZE )
220
+ cv .NamedWindow ("west" ,cv .CV_WINDOW_NORMAL )
221
+ cv .NamedWindow ("east" ,cv .CV_WINDOW_NORMAL )
222
222
223
223
#address of the control server
224
224
ip = "md-red5.discovery.wisc.edu"
225
225
port = 7779
226
226
size = 1024
227
227
228
228
#first get a connection to the server
229
- # s = connect(ip,port)
229
+ s = connect (ip ,port )
230
230
231
231
232
232
while (1 ):
@@ -238,6 +238,9 @@ def procImg(img,sideName):
238
238
frame_west = cv .LoadImageM (fname_west ,cv .CV_LOAD_IMAGE_COLOR );
239
239
frame_east = cv .LoadImageM (fname_east ,cv .CV_LOAD_IMAGE_COLOR );
240
240
241
+ #small_west
242
+ #small_east =
243
+
241
244
#find the blimp with one camera
242
245
centroids = procImg (frame_west ,"west" )
243
246
centx_west = centroids [0 ]
@@ -255,23 +258,23 @@ def procImg(img,sideName):
255
258
cv .WaitKey (100 )
256
259
257
260
#get the 3D location of the blimp
258
- triang_3D (centx_west , centy_west , centx_east , centy_east )
261
+ coord3D = triang_3D (centx_west , centy_west , centx_east , centy_east )
259
262
260
- print ("x_3d: " + str (x_3d [0 ]))
261
- print ("y_3d: " + str (y_3d [ 0 ]))
262
- print ("z_3d: " + str (z_3d [ 0 ]))
263
+ print ("x_3d: " + str (coord3D [0 ]))
264
+ print ("y_3d: " + str (coord3D [ 1 ]))
265
+ print ("z_3d: " + str (coord3D [ 2 ]))
263
266
print ("-----------------------------------" )
264
267
265
268
#send the 3D location to the control server
266
- ## try:
267
- ## #x,y,z = getPosition()
268
- ## msg = "" + str(x_3d [0]) + "," + str(y_3d[0 ]) + "," + str(z_3d[0 ]) + "\n"
269
- ## s.send(msg)
270
- ## #time.sleep(1)
271
- ## except Exception as err:
272
- ## print("disconnected")
273
- ## #we got disconnected somehow, reconnect
274
- ## s = connect(ip,port)
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 )
275
278
276
279
277
280
0 commit comments