I am using opencv2.4.10 with python and I am trying to draw some contours of moving objects. Unfortunately I cannot figure out what am I doing wrong.
First of all I use Background Subtractor from opencv ( cv2.BackgroundSubtractorMOG2
). It works fine, I can see my moving objects separated from the background.
After separation I use cv2.FindContours
method. It also works fine and I can print contorus as list of numbers.
But then, when I am trying to draw contours on the original image frame an error occurs.
cv2.drawContours(frame, contours, 1, (0, 255, 0), 3)
cv2.error: ..\..\..\..\opencv\modules\imgproc\src\contours.cpp:1810: error: (-215) 0 <= contourIdx && contourIdx < (int)last in function cv::drawContours
Could you comment on this issue?
From the error message we can get conditions that have to be met: 0 <= contourIdx
&& contourIdx < (int)last
Focusing on the second part, contourIdx < (int)last
, I'd guess that you may be trying to draw the second contour of a list that's only got either one or zero contours.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.