简体   繁体   English

使用python和opencv绘制检测到的对象的轮廓

[英]Draw contours of detected objects using python and opencv

I am using opencv2.4.10 with python and I am trying to draw some contours of moving objects. 我正在将opencv2.4.10与python配合使用,并且尝试绘制运动对象的轮廓。 Unfortunately I cannot figure out what am I doing wrong. 不幸的是,我无法弄清楚我在做什么错。

First of all I use Background Subtractor from opencv ( cv2.BackgroundSubtractorMOG2 ). 首先,我使用opencv的Background Subtractor( cv2.BackgroundSubtractorMOG2 )。 It works fine, I can see my moving objects separated from the background. 效果很好,我可以看到移动的物体与背景分离。

After separation I use cv2.FindContours method. 分离后,我使用cv2.FindContours方法。 It also works fine and I can print contorus as list of numbers. 它也可以正常工作,我可以将contorus作为数字列表打印。

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 从错误消息中,我们可以得到必须满足的条件: 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. 关注第二部分, contourIdx < (int)last ,我想您可能正在尝试绘制仅具有一个或零个轮廓的列表的第二个轮廓。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM