我得到了这个错误:
OpenCV Error: Assertion failed (hpoints > 0) in cv::convexityDefects, file C:\projects\opencv-python\opencv\modules\imgproc\src\convhull.cpp, line 284
Traceback (most recent call last):
File "E:/PycharmProjects/ComputerVisionAgain/Image Segmentation/hand_blk/main.py", line 12, in <module>
hull_defects=cv2.convexityDefects(sorted_cnts[0],hull)
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\convhull.cpp:284: error: (-215) hpoints > 0 in function cv::convexityDefects
当我试图得到图像最大轮廓的凸度缺陷时。 这是我使用的代码:
^{pr2}$
cv2.convexHull
默认情况下以一组点的形式返回凸包(returnPoints参数对此负责,默认为True,docs here)。但是cv2.convexityDefects
函数,根据docs,期望第二个参数是使外壳的轮廓点的索引。在所以换个衣服吧
到
^{pr2}$因此
hull
将包含构成凸壳的原始sorted_cnts[0]
轮廓的索引。在顺便说一句,在这种情况下,你仍然可以通过做
sorted_cnts[0][hull]
获得作为一组点的外壳。在相关问题 更多 >
编程相关推荐