OpenCV contourArea异常

时间:2017-12-01 16:43:40

标签: python opencv

我是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

1 个答案:

答案 0 :(得分:1)

cv2.findContours返回<audio class="my-audio"> <source src="https://www.w3schools.com/tags/mov_bbb.mp4" type="audio/ogg"> </audio>,请参阅文档here

切换通话中的顺序,它应该有效。

同样见this question