0
我是OpenCV-Python的新手。
我想获得convexityDefects,我有以下代码,如下所示。OpenCV-Python中的凸性缺陷
import cv2
import numpy as np
img = cv2.imread('s4.png')
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img_gray, 127, 255,0)
contours,hierarchy = cv2.findContours(thresh,2,1)
cnt = contours[0]
hull = cv2.convexHull(cnt,returnPoints = False)
defects = cv2.convexityDefects(cnt,hull)
# some codes here.....
但是,当我跑我得到一个错误代码..
Traceback (most recent call last):
File "C:/Users/jasonc/Desktop/Pyhton/convexityDefects", line 11, in <module>
defects = cv2.convexityDefects(cnt,hull)
error: ..\..\..\OpenCV-2.4.4\modules\imgproc\src\contours.cpp:1969: error: (-215) ptnum > 3
有什么不对?我搜索了互联网,大部分的例子看起来都一样。
因此,您需要超过3分的凸性缺陷。确保cnt包含3个以上的元素。 – berak 2014-11-05 06:32:40
当我打印出cnt时,我得到了这个结果:[[[394 638]] [[395 638]]]。我现在应该怎么做? – user3988645 2014-11-05 07:39:20