Ask Your Question
0

Bounding box not showing?

asked 2017-03-18 12:12:43 -0600

achima gravatar image

updated 2017-04-26 18:44:04 -0600

I am writing code to be able to detect moving objects in a video. I have blurred the video, computed the difference between the first and current frame, found contours and computed the bounding box. In theory, my code should draw the bounding box over the moving objects, but nothing is showing up. There is no error message either, so I can't see what it is that it incorrect.

Any help is appreciated!

edit retag flag offensive close merge delete

Comments

which opencv version is it, exactly ?

and, shouldn't cv2.rectangle be inside the for loop ? (indentation problem)

berak gravatar imageberak ( 2017-03-18 12:21:24 -0600 )edit

Yes, I think that was an error from copying the code over, its the same indentation as the line above in my code. cv2 version is 3.1.0

achima gravatar imageachima ( 2017-03-18 12:30:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-18 12:41:34 -0600

berak gravatar image

updated 2017-03-18 13:22:33 -0600

if you're using opencv3:

>>> help(cv2.findContours)

findContours(...)
 findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> image, contours, hierarchy

i'd say, cv2.findContours(....)[0] is wrong, and that it has to be: cv2.findContours(....)[1] instead.

(in other words, make sure to feed the contours into the boundingRect(), not the image)

edit flag offensive delete link more

Comments

Thanks, I've changed the line to

cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1] The bounding box now shows, but there are many boxes that appear on each car, instead of just the one.

achima gravatar imageachima ( 2017-03-18 12:48:09 -0600 )edit
1

No worries, I've changed the number of iterations and it has gotten rid of most of the small boxes.

achima gravatar imageachima ( 2017-03-18 12:54:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-18 12:12:43 -0600

Seen: 874 times

Last updated: Apr 26 '17