【发布时间】:2017-01-21 08:32:25
【问题描述】:
我正在尝试对从 findContours 获得的轮廓进行简单的面积计算。 我的 openCv 版本是 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 结果与轮廓区域的类型匹配
谢谢:)
编辑:原来我需要使用 findContours 的第二个参数
im2, cc, hierarchy = cv2.findContours(im_bw.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
【问题讨论】:
-
你检查过 cc[0] 是否为空吗?
-
挖多了才发现,原来我需要得到findContours的第二个参数