@@ -62,8 +62,8 @@ def triang_3D(col_1, row_1, col_2, row_2) :
62
62
#P2 = np.array([[-49.3179, -518.1547, -4126.6037, 847220.0489], [-1776.8193, 738.4249, -127.1965, 963513.3797], [0.2075, 0.9387, -0.2753, 1589.9759]])
63
63
#P2 = np.array([[2.1, 0.0, -3.64, -34048.4],[0.0, -4.2, 0.0, 18186.0],[-0.866, 0.0, -0.5, 44521.3]])
64
64
#P2 = np.array([[2.100000, 1.651303, -3.240864, -46414.721975],[0.000000, -3.742227, -1.906760, 43391.754855],[-0.866025, 0.226995, -0.445503, 42821.420363]])
65
- P1 = np .array ([[- 1.173428 ,- 0.688810 ,- 3.973488 ,47750.246983 ],[- 0.169082 ,4.143045 ,- 0.668271 ,- 12800.579085 ],{ 0.959334 ,- 0.006367 ,- 0.282201 ,3183.078361 ]])
66
- P2 = np .array ([[2.655326 ,1.495096 ,- 2.890317 ,- 51294.190875 ],[0.815836 ,- 3.917179 ,- 1.276762 ,34865.251439 ],{ - 0.750044 ,0.058514 ,- 0.658795 ,33903.280179 ]])
65
+ P1 = np .array ([[- 1.173428 ,- 0.688810 ,- 3.973488 ,47750.246983 ],[- 0.169082 ,4.143045 ,- 0.668271 ,- 12800.579085 ],[ 0.959334 ,- 0.006367 ,- 0.282201 ,3183.078361 ]])
66
+ P2 = np .array ([[2.655326 ,1.495096 ,- 2.890317 ,- 51294.190875 ],[0.815836 ,- 3.917179 ,- 1.276762 ,34865.251439 ],[ - 0.750044 ,0.058514 ,- 0.658795 ,33903.280179 ]])
67
67
68
68
#blimp position from camera 1
69
69
#col_1 = 396
@@ -164,32 +164,44 @@ def getthresholdedimg(im):
164
164
165
165
# this function take RGB image.Then converts it into HSV for easy colour detection
166
166
# Threshold it with yellow and blue part as white and all other regions as black.Then return that image
167
- RED_MIN = cv .Scalar (0 ,140 ,140 )
168
- RED_MAX = cv .Scalar (5 ,255 ,255 )
167
+ RED_MIN1 = cv .Scalar (0 ,100 ,150 )
168
+ RED_MAX1 = cv .Scalar (2 ,255 ,255 )
169
+ RED_MIN2 = cv .Scalar (170 ,100 ,150 )
170
+ RED_MAX2 = cv .Scalar (180 ,255 ,255 )
171
+ YEL_MIN = cv .Scalar (22 ,90 ,90 )
172
+ YEL_MAX = cv .Scalar (25 ,255 ,255 )
173
+
169
174
170
175
global imghsv
171
176
imghsv = cv .CreateImage (cv .GetSize (im ),8 ,3 )
172
177
173
178
# Convert image from RGB to HSV
174
179
cv .CvtColor (im ,imghsv ,cv .CV_BGR2HSV )
175
180
176
- # creates images for blue
177
- imgblue = cv .CreateImage (cv .GetSize (im ),8 ,1 )
181
+ # creates images for red
182
+ imgred1 = cv .CreateImage (cv .GetSize (im ),8 ,1 )
183
+ imgred2 = cv .CreateImage (cv .GetSize (im ),8 ,1 )
184
+
185
+ # image for yellow
186
+ imgyellow = cv .CreateImage (cv .GetSize (im ),8 ,1 )
178
187
179
188
# creates blank image to which color images are added
180
189
imgthreshold = cv .CreateImage (cv .GetSize (im ),8 ,1 )
181
190
182
191
# determine HSV color thresholds for yellow, blue, and green
183
192
# cv.InRange(src, lowerbound, upperbound, dst)
184
- # for imgblue, lowerbound is 95, and upperbound is 115
185
- # for red, 0 to 60
186
- cv .InRangeS (imghsv , RED_MIN , RED_MAX , imgblue )
193
+ cv .InRangeS (imghsv , RED_MIN1 , RED_MAX1 , imgred1 )
194
+ cv .InRangeS (imghsv , RED_MIN2 , RED_MAX2 , imgred2 )
195
+ cv .InRangeS (imghsv , YEL_MIN , YEL_MAX , imgyellow )
196
+
187
197
188
198
# add color thresholds to blank 'threshold' image
189
- cv .Add (imgthreshold , imgblue , imgthreshold )
199
+ cv .Add (imgthreshold , imgred1 , imgthreshold )
200
+ cv .Add (imgthreshold , imgred2 , imgthreshold )
201
+ cv .Add (imgthreshold , imgyellow , imgthreshold )
190
202
191
203
#return imgthreshold
192
- return imgblue
204
+ return imgthreshold
193
205
#---------------------------------------------------------
194
206
#img is an image (passed in by reference)
195
207
#sideName is for output printing purposes
@@ -201,20 +213,20 @@ def procImg(img,sideName,dispFlag):
201
213
#put the smoothed image here
202
214
imgSmooth = cv .CreateImage (cv .GetSize (img ), 8 , 3 )
203
215
#put thresholded image here
204
- imgMask = cv .CreateImage (cv .GetSize (img ), 8 , 1 )
216
+ imgMask = cv .CreateImage (cv .GetSize (img ), 1 , 1 )
205
217
206
218
cv .SetZero (imdraw )
207
- cv .Smooth (img , imgSmooth , cv .CV_GAUSSIAN , 5 , 0 ) #Gaussian filter the image
208
- imgbluethresh = getthresholdedimg (imgSmooth ) #Get a color thresholed binary image
209
- cv .Smooth (imgbluethresh , imgbluethresh , cv .CV_GAUSSIAN , 5 , 0 ) #Gaussian filter the image
210
- # imgMask = imgbluethresh
219
+ # cv.Smooth(img, imgSmooth, cv.CV_GAUSSIAN, 13 , 0) #Gaussian filter the image
220
+ imgthresh = getthresholdedimg (img ) #Get a color thresholed binary image
221
+ # cv.Smooth(imgbluethresh, imgbluethresh, cv.CV_GAUSSIAN, 5, 0) #Gaussian filter the image
222
+ imgMask = imgthresh
211
223
#imgbluethresh = imgMask
212
- cv .Erode (imgbluethresh , imgbluethresh , None , 3 )
213
- cv .Dilate (imgbluethresh , imgbluethresh , None , 10 )
214
- imgMask = imgbluethresh
224
+ cv .Erode (imgMask , imgMask , None , 6 )
225
+ cv .Dilate (imgMask , imgMask , None , 10 )
226
+
215
227
#img2 = cv.CloneImage(imgbluethresh)
216
228
storage = cv .CreateMemStorage (0 )
217
- contour = cv .FindContours (imgbluethresh , storage , cv .CV_RETR_CCOMP , cv .CV_CHAIN_APPROX_SIMPLE )
229
+ contour = cv .FindContours (imgMask , storage , cv .CV_RETR_CCOMP , cv .CV_CHAIN_APPROX_SIMPLE )
218
230
219
231
centroidx = 0
220
232
centroidy = 0
@@ -231,13 +243,13 @@ def procImg(img,sideName,dispFlag):
231
243
area = bound_rect [2 ]* bound_rect [3 ];
232
244
233
245
#if dispFlag:
234
- # print("Area= " + str(area))
246
+ print ("Area= " + str (area ))
235
247
236
248
#Largest area over 5000 pixels
237
- if (area > 5000 ) and (area > prevArea ):
249
+ if (area > 2000 ) and (area > prevArea ):
238
250
pt1 = (bound_rect [0 ], bound_rect [1 ])
239
251
pt2 = (bound_rect [0 ] + bound_rect [2 ], bound_rect [1 ] + bound_rect [3 ])
240
- prevArea = area
252
+ prevArea = area
241
253
242
254
# Draw bounding rectangle
243
255
cv .Rectangle (img , pt1 , pt2 , cv .CV_RGB (255 ,0 ,0 ), 3 )
@@ -259,7 +271,7 @@ def procImg(img,sideName,dispFlag):
259
271
print ("" )
260
272
261
273
if dispFlag :
262
- small_thresh = cv .CreateImage ((int (dispScale1 * cv .GetSize (imgbluethresh )[0 ]), int (dispScale1 * cv .GetSize (imgbluethresh )[1 ])), 8 , 1 )
274
+ small_thresh = cv .CreateImage ((int (dispScale1 * cv .GetSize (imgMask )[0 ]), int (dispScale1 * cv .GetSize (imgMask )[1 ])), 8 , 1 )
263
275
cv .Resize (imgMask , small_thresh )
264
276
cv .Threshold (small_thresh , small_thresh , 0 , 255 , cv .CV_THRESH_BINARY )
265
277
cv .ShowImage (sideName + "_threshold" , small_thresh )
@@ -369,7 +381,7 @@ def procImg(img,sideName,dispFlag):
369
381
fname_west = westList [imgIdx ]
370
382
fname_east = eastList [imgIdx ]
371
383
#imgIdx = (imgIdx + 1)%(totImg) -> Update below
372
- # cv.WaitKey(2000 ) #wait for 2 seconds so I can see the output
384
+ cv .WaitKey (3000 ) #wait for 2 seconds so I can see the output
373
385
374
386
#open the images from file
375
387
frame_west = cv .LoadImage (fname_west ,cv .CV_LOAD_IMAGE_COLOR );
0 commit comments