【问题标题】:OpenCV contourArea exception [duplicate]OpenCV轮廓区域异常[重复]
【发布时间】:2018-05-15 19:36:19
【问题描述】:

我对opencv很陌生,我有一个问题:

#Find contours of the filtered frame
contours, hierarchy, _= cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)   

#Draw Contours
#cv2.drawContours(frame, cnt, -1, (122,122,0), 3)
#cv2.imshow('Dilation',median)

#Find Max contour area (Assume that hand is in the frame)
max_area=100
ci=0    
for i in range(len(contours)):
    cnt=contours[i]
    area = cv2.contourArea(cnt)
    if(area>max_area):
        max_area=area
        ci=i

我在互联网上找到了这个,一些手部追踪的东西,但我得到了这个例外:

File "C:\Users\123\Desktop\cv\track.py", line 87, 
in<module>
area = cv2.contourArea(cnt)
error: C:\projects\opencv-
python\opencv\modules\imgproc\src\shapedescr.cpp:320: error: (-215) npoints 
>= 0 && (depth == CV_32F || depth == CV_32S) in function cv::contourArea

您能告诉我为什么会发生这种情况以及解决方案是什么吗? 我正在使用 Python 2.7.13 和 OpenCV 3.3.0 版。 完整代码在这里:pastebin

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    cv2.findContours 返回img, contours, hierarchy,请参阅文档here

    在您的通话中切换顺序,它应该可以工作。

    也请参阅this question

    【讨论】:

    • 非常感谢您的完美工作。
    • 那么请考虑接受我的回答:)
    猜你喜欢
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多