与openCV 3中contourArea的兼容性问题 [英] compatibility issue with contourArea in openCV 3
本文介绍了与openCV 3中contourArea的兼容性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试对从findContours获得的轮廓进行简单的面积计算. 我的openCv版本是3.1.0
I am trying to do a simple area calculation of contours I get from findContours. My openCv version is 3.1.0
我的代码是:
cc = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.contourArea(cc[0])
error: 'C:\\builds\\master_PackSlaveAddon-win32-vc12-static\\opencv\\modules\\imgproc\\src\\shapedescr.cp...: error: (-215) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function cv::contourArea\n'
似乎无法解决这个问题,我感觉它只是进行了类型转换,我希望findContours结果能够与contourArea的类型相匹配
Cant seem to solve it, I have a feeling its just typecasting altough I expect the findContours result to match the type of contourArea
谢谢:)
原来我需要使用findContours的第二个参数
turns out I need to take the 2nd argument of findContours
im2, cc, hierarchy = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
推荐答案
在Opencv 3 API版本中,cv2.findContours()
返回3
In Opencv 3 API version the cv2.findContours()
returns 3 objects
- 图片
- 轮廓
- 层次结构
因此,您需要将语句重写为:
So you need to rewrite your statement as:
image, contours, hierarchy = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
这篇关于与openCV 3中contourArea的兼容性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文