我是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
出了什么问题?我搜索了互联网,大部分示例看起来都一样。