@@ -73,6 +73,14 @@ def triang_3D(col_1, row_1, col_2, row_2) :
73
73
row_1 = (row_1 - 360 )* 0.00475
74
74
row_2 = (row_2 - 360 )* 0.00475
75
75
76
+ print ("west side centroid x: " + str (col_1 ) + " y: " + str (row_1 ) + " mm" )
77
+ print ("east side centroid x: " + str (col_2 ) + " y: " + str (row_2 ) + " mm" )
78
+
79
+ #col_1 = 0.8117
80
+ #row_1 = -0.9851
81
+ #col_2 = -1.0373
82
+ #row_2 = 0.42232
83
+
76
84
77
85
#translated from matlab:
78
86
@@ -150,31 +158,34 @@ def triang_3D(col_1, row_1, col_2, row_2) :
150
158
#---------------------------------------------------------
151
159
def getthresholdedimg (im ):
152
160
153
- # this function take RGB image.Then convert it into HSV for easy colour detection
154
- # and threshold it with yellow and blue part as white and all other regions as black.Then return that image
155
-
156
- global imghsv
157
- imghsv = cv .CreateImage (cv .GetSize (im ),8 ,3 )
158
-
159
- # Convert image from RGB to HSV
160
- cv .CvtColor (im ,imghsv ,cv .CV_BGR2HSV )
161
-
162
- # creates images for blue
163
- imgblue = cv .CreateImage (cv .GetSize (im ),8 ,1 )
164
-
165
- # creates blank image to which color images are added
166
- imgthreshold = cv .CreateImage (cv .GetSize (im ),8 ,1 )
167
-
168
- # determine HSV color thresholds for yellow, blue, and green
169
- # cv.InRange(src, lowerbound, upperbound, dst)
170
- # for imgblue, lowerbound is 95, and upperbound is 115
171
- cv .InRangeS (imghsv , cv .Scalar (55 ,110 ,110 ), cv .Scalar (155 ,255 ,255 ), imgblue )
172
-
173
- # add color thresholds to blank 'threshold' image
174
- cv .Add (imgthreshold , imgblue , imgthreshold )
175
-
176
- #return imgthreshold
177
- return imgblue
161
+ # this function take RGB image.Then converts it into HSV for easy colour detection
162
+ # Threshold it with yellow and blue part as white and all other regions as black.Then return that image
163
+ RED_MIN = cv .Scalar (0 ,140 ,140 )
164
+ RED_MAX = cv .Scalar (5 ,255 ,255 )
165
+
166
+ global imghsv
167
+ imghsv = cv .CreateImage (cv .GetSize (im ),8 ,3 )
168
+
169
+ # Convert image from RGB to HSV
170
+ cv .CvtColor (im ,imghsv ,cv .CV_BGR2HSV )
171
+
172
+ # creates images for blue
173
+ imgblue = cv .CreateImage (cv .GetSize (im ),8 ,1 )
174
+
175
+ # creates blank image to which color images are added
176
+ imgthreshold = cv .CreateImage (cv .GetSize (im ),8 ,1 )
177
+
178
+ # determine HSV color thresholds for yellow, blue, and green
179
+ # cv.InRange(src, lowerbound, upperbound, dst)
180
+ # for imgblue, lowerbound is 95, and upperbound is 115
181
+ # for red, 0 to 60
182
+ cv .InRangeS (imghsv , RED_MIN , RED_MAX , imgblue )
183
+
184
+ # add color thresholds to blank 'threshold' image
185
+ cv .Add (imgthreshold , imgblue , imgthreshold )
186
+
187
+ #return imgthreshold
188
+ return imgblue
178
189
#---------------------------------------------------------
179
190
#img is an image (passed in by reference)
180
191
#sideName is for output printing purposes
@@ -189,11 +200,14 @@ def procImg(img,sideName,dispFlag):
189
200
imgMask = cv .CreateImage (cv .GetSize (img ), 8 , 1 )
190
201
191
202
cv .SetZero (imdraw )
192
- cv .Smooth (img , imgSmooth , cv .CV_GAUSSIAN , 3 , 0 ) #Gaussian filter the image
193
- imgbluethresh = getthresholdedimg (img ) #Get a color thresholed binary image
194
- imgMask = imgbluethresh
203
+ cv .Smooth (img , imgSmooth , cv .CV_GAUSSIAN , 5 , 0 ) #Gaussian filter the image
204
+ imgbluethresh = getthresholdedimg (imgSmooth ) #Get a color thresholed binary image
205
+ cv .Smooth (imgbluethresh , imgbluethresh , cv .CV_GAUSSIAN , 5 , 0 ) #Gaussian filter the image
206
+ #imgMask = imgbluethresh
207
+ #imgbluethresh = imgMask
195
208
cv .Erode (imgbluethresh , imgbluethresh , None , 3 )
196
209
cv .Dilate (imgbluethresh , imgbluethresh , None , 10 )
210
+ imgMask = imgbluethresh
197
211
#img2 = cv.CloneImage(imgbluethresh)
198
212
storage = cv .CreateMemStorage (0 )
199
213
contour = cv .FindContours (imgbluethresh , storage , cv .CV_RETR_CCOMP , cv .CV_CHAIN_APPROX_SIMPLE )
@@ -213,11 +227,12 @@ def procImg(img,sideName,dispFlag):
213
227
area = bound_rect [2 ]* bound_rect [3 ];
214
228
215
229
#if dispFlag:
216
- # print("Area= " + str(area))
230
+ #print("Area= " + str(area))
217
231
218
- if (area > prevArea and area > 3000 ):
232
+ if (area > 5000 ) and ( area > prevArea ):
219
233
pt1 = (bound_rect [0 ], bound_rect [1 ])
220
- pt2 = (bound_rect [0 ] + bound_rect [2 ], bound_rect [1 ] + bound_rect [3 ])
234
+ pt2 = (bound_rect [0 ] + bound_rect [2 ], bound_rect [1 ] + bound_rect [3 ])
235
+ prevArea = area
221
236
222
237
# Draw bounding rectangle
223
238
cv .Rectangle (img , pt1 , pt2 , cv .CV_RGB (255 ,0 ,0 ), 3 )
@@ -228,9 +243,7 @@ def procImg(img,sideName,dispFlag):
228
243
229
244
if (centroidx == 0 or centroidy == 0 ):
230
245
print ("no blimp detected from " + sideName )
231
- else :
232
- print (sideName + " centroid x:" + str (centroidx ))
233
- print (sideName + " centroid y:" + str (centroidy ))
246
+
234
247
235
248
print ("" )
236
249
@@ -282,15 +295,17 @@ def procImg(img,sideName,dispFlag):
282
295
#Live images from the IP cameras
283
296
#(if not live, then this file needs to be in folder with a bunch of images)
284
297
#(if live, then need to be local at WID)
285
- liveIP = 1
298
+ liveIP = 0
286
299
if liveIP == 0 :
287
300
#need to be in directory with a bunch of images
288
- dirList = os .listdir (os .getcwd ())
301
+ #dirList = os.listdir(os.getcwd())
302
+ dirName = 'E:\\ Google Drive\\ Medical_Physics\\ Blimp\\ 2013-09-19\\ 15,10,7.32\\ '
303
+ dirList = os .listdir (dirName )
289
304
num_base = 0
290
- both_offset = 10
291
- num_imgs = 145 - both_offset
305
+ both_offset = 0
306
+ num_imgs = 5 - both_offset
292
307
east_offset = 0 + both_offset
293
- west_offset = 147 + both_offset
308
+ west_offset = num_imgs + both_offset
294
309
295
310
296
311
#address of the control server
@@ -310,12 +325,13 @@ def procImg(img,sideName,dispFlag):
310
325
#capture images from cameras, store images to file
311
326
urllib .urlretrieve (url_west ,fname_west )
312
327
urllib .urlretrieve (url_east ,fname_east )
313
- else :
314
- num_base = ( num_base + 1 ) % ( num_imgs )
328
+ else :
329
+ print ( "image # = " + str ( num_base ) )
315
330
west_num = west_offset + num_base
316
331
east_num = east_offset + num_base
317
- fname_west = dirList [west_num ]
318
- fname_east = dirList [east_num ]
332
+ fname_west = dirName + dirList [west_num ]
333
+ fname_east = dirName + dirList [east_num ]
334
+ num_base = (num_base + 1 )% (num_imgs )
319
335
cv .WaitKey (2000 ) #wait for 2 seconds so I can see the output
320
336
321
337
#open the images from file
@@ -349,9 +365,9 @@ def procImg(img,sideName,dispFlag):
349
365
#get the 3D location of the blimp
350
366
coord3D = triang_3D (centx_west , centy_west , centx_east , centy_east )
351
367
352
- print ("x_3d: " + str (coord3D [0 ]))
353
- print ("y_3d: " + str (coord3D [1 ]))
354
- print ("z_3d: " + str (coord3D [2 ]))
368
+ print ("x_3d: " + str (coord3D [0 ]) + "mm" )
369
+ print ("y_3d: " + str (coord3D [1 ]) + "mm" )
370
+ print ("z_3d: " + str (coord3D [2 ]) + "mm" )
355
371
print ("err1: " + str (coord3D [3 ]))
356
372
print ("err2: " + str (coord3D [4 ]))
357
373
0 commit comments