python - OpenCV 轮廓区域异常

标签 python opencv

这个问题在这里已经有了答案:





compatibility issue with contourArea in openCV 3

(4 个回答)


4年前关闭。




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

我在互联网上找到了这个,一些手部追踪的东西,但我得到了这个异常(exception):
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

最佳答案

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

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

this question以及。

关于python - OpenCV 轮廓区域异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47597759/

相关文章:

python - 如何使用 Python 创建非常具体的数据图

python - 如何自动化 python 日志记录

c++ - 模块/videoio/cmake/detect_ffmpeg.cmake :16 处的 CMake 错误

python - 使用 python opencv 在网络摄像头上切换图像过滤器

c++ - 使用 Mat opencv 组合矩阵

python - 从 GML 文件中提取数据

python - 使用 selenium 和 python 在网页网格中抓取 javascript 数据

python - 根据关闭日期时间属性对对象列表进行分组

c++ - 以 SVM 作为弱学习器的 Opencv 级联分类器

opencv - 使用 OpenCV 的帧中有多少白色?