7
7
import numpy as np
8
8
from numpy import linalg as LA
9
9
10
+ import socket
11
+ import time
12
+
10
13
global imghsv
11
14
global x_3d , y_3d , z_3d
12
15
26
29
27
30
# to modify color thresholds, change the cv.Scalar values in the InRange method in the gettresholdedimg function below
28
31
32
+ def connect (ip ,port ):
33
+ #make a client socket
34
+
35
+ s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
36
+ s .settimeout (1 )
37
+ #keep trying to connect to the server until success
38
+ print ("connecting to control server..." )
39
+ connected = False
40
+ #while not connected:
41
+ try :
42
+ s .connect ((ip , port ))
43
+ connected = True
44
+ except Exception as err :
45
+ pass
46
+ #print("connected")
47
+ return s
29
48
30
49
#The following function takes coordinates from the images and convertes them to 3D spatial positions
31
50
#The calibration constants are in R1, T1, R2, and T2 for cameras 1 (west) and 2 (east)
@@ -160,6 +179,14 @@ def getthresholdedimg(im):
160
179
# blank lists to store coordinates of blue blob
161
180
blue = []
162
181
182
+ #address of the control server
183
+ ip = "md-red5.discovery.wisc.edu"
184
+ port = 7779
185
+ size = 1024
186
+
187
+ #first get a connection to the server
188
+ s = connect (ip ,port )
189
+
163
190
while (1 ):
164
191
urllib .urlretrieve (url_west ,fname_west )
165
192
urllib .urlretrieve (url_east ,fname_east )
@@ -181,6 +208,10 @@ def getthresholdedimg(im):
181
208
contour = cv .FindContours (imgbluethresh , storage , cv .CV_RETR_CCOMP , cv .CV_CHAIN_APPROX_SIMPLE )
182
209
# blank list into which points for bounding rectangles around blobs are appended
183
210
points = []
211
+
212
+ centroidx = 0
213
+ centroidy = 0
214
+
184
215
while contour :
185
216
186
217
# Draw bounding rectangles
@@ -296,8 +327,20 @@ def getthresholdedimg(im):
296
327
297
328
triang_3D (centx_west , centy_west , centx_east , centy_east )
298
329
299
- print ("x_3d: " + str (x_3d ))
300
- print ("y_3d: " + str (y_3d ))
301
- print ("z_3d: " + str (z_3d ))
330
+ print ("x_3d: " + str (x_3d [0 ]))
331
+ print ("y_3d: " + str (y_3d [0 ]))
332
+ print ("z_3d: " + str (z_3d [0 ]))
333
+
334
+ try :
335
+ #x,y,z = getPosition()
336
+ msg = "" + str (x_3d [0 ]) + "," + str (y_3d [0 ]) + "," + str (z_3d [0 ]) + "\n "
337
+ s .send (msg )
338
+ #time.sleep(1)
339
+ except Exception as err :
340
+ print ("disconnected" )
341
+ #we got disconnected somehow, reconnect
342
+ s = connect (ip ,port )
343
+
344
+
302
345
303
346
######################################################
0 commit comments