Ask Your Question

Bounding box not showing?

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

achima gravatar image

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

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


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 -0500 )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 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

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

berak gravatar image

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

if you're using opencv3:

>>> help(cv2.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


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 -0500 )edit

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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 96 times

Last updated: Apr 26