Skip to content

Commit 93093c2

Browse files
committed
Display non-smoothed image
1 parent 23e3e3f commit 93093c2

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

BlimpDetect-8-28_JB.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import time
1111

1212
global imghsv
13-
global x_3d, y_3d, z_3d
1413

1514
# purpose: using HSV thresholds, detects blue, yellow and purple objects in a video stream in three new windows
1615
# 1) a black/white stream showing objects matching threshold values (window "threshold")
@@ -35,6 +34,7 @@ def connect(ip,port):
3534
s.settimeout(1)
3635
#keep trying to connect to the server until success
3736
print("connecting to control server...")
37+
print("")
3838
connected = False
3939
#while not connected:
4040
try:
@@ -51,7 +51,7 @@ def connect(ip,port):
5151
#These constants are produced by matlab code that is available here:
5252
#http://www.vision.caltech.edu/bouguetj/calib_doc/
5353
def triang_3D(col_1, row_1, col_2, row_2) :
54-
global x_3d, y_3d, z_3d
54+
5555
#R matrix for camera 1 (west side)
5656
R1 = np.array([[-74.2709, 637.41, -255.7461], [865.2027, 273.6518, -92.0415], [0.1602, 0.3172, -0.9347]])
5757
#T matrix for camera 1
@@ -121,9 +121,7 @@ def triang_3D(col_1, row_1, col_2, row_2) :
121121
y_coord = y0+b*r[0]
122122
z_coord = z0+c*r[0]
123123

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])
127125

128126
#---------------------------------------------------------
129127
def getthresholdedimg(im):
@@ -160,10 +158,12 @@ def procImg(img,sideName):
160158

161159
#creates empty images of the same size
162160
imdraw = cv.CreateImage(cv.GetSize(img), 8, 3)
161+
#put the smoothed image here
162+
imgSmooth = cv.CreateImage(cv.GetSize(img), 8, 3)
163163

164164
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
167167
cv.Erode(imgbluethresh, imgbluethresh, None, 3)
168168
cv.Dilate(imgbluethresh, imgbluethresh, None, 10)
169169
img2 = cv.CloneImage(imgbluethresh)
@@ -217,16 +217,16 @@ def procImg(img,sideName):
217217
url_west = 'http://10.129.20.12/snapshot/view0.jpg'
218218

219219
# 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)
222222

223223
#address of the control server
224224
ip = "md-red5.discovery.wisc.edu"
225225
port = 7779
226226
size = 1024
227227

228228
#first get a connection to the server
229-
#s = connect(ip,port)
229+
s = connect(ip,port)
230230

231231

232232
while(1):
@@ -238,6 +238,9 @@ def procImg(img,sideName):
238238
frame_west = cv.LoadImageM(fname_west,cv.CV_LOAD_IMAGE_COLOR);
239239
frame_east = cv.LoadImageM(fname_east,cv.CV_LOAD_IMAGE_COLOR);
240240

241+
#small_west
242+
#small_east =
243+
241244
#find the blimp with one camera
242245
centroids = procImg(frame_west,"west")
243246
centx_west = centroids[0]
@@ -255,23 +258,23 @@ def procImg(img,sideName):
255258
cv.WaitKey(100)
256259

257260
#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)
259262

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]))
263266
print("-----------------------------------")
264267

265268
#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)
275278

276279

277280

0 commit comments

Comments
 (0)