Opencv:凸面缺陷最大的轮廓

2024-06-10 07:19:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到了这个错误:

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}$

This is the original image

This is threshed image

This is convex hulled image on largest contour


Tags: insrcmoduleslineerrorcv2opencvcpp
1条回答
网友
1楼 · 发布于 2024-06-10 07:19:43

cv2.convexHull默认情况下以一组点的形式返回凸包(returnPoints参数对此负责,默认为Truedocs here)。但是cv2.convexityDefects函数,根据docs,期望第二个参数是使外壳的轮廓点的索引。在

所以换个衣服吧

hull=cv2.convexHull(sorted_cnts[0])

^{pr2}$

因此hull将包含构成凸壳的原始sorted_cnts[0]轮廓的索引。在

顺便说一句,在这种情况下,你仍然可以通过做sorted_cnts[0][hull]获得作为一组点的外壳。在

相关问题 更多 >