Я получаю эту ошибку:
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
когда я пытаюсь получить выпуклость дефектов самого большого контура изображения.
Это код, который я использую:
import cv2
import numpy as np
img=cv2.imread('blk_hand.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh=cv2.threshold(gray,100,255,cv2.THRESH_BINARY)
_,contours,h=cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
sorted_cnts=sorted(contours,key=cv2.contourArea,reverse=True)
hull=cv2.convexHull(sorted_cnts[0])
hull_defects=cv2.convexityDefects(sorted_cnts[0],hull)
cv2.drawContours(img,[hull],-1,(0,0,255),3)
cv2.drawContours(img,sorted_cnts[0],-1,(0,255,0),3)
cv2.imshow('img',img)
cv2.imshow('thresh',thresh)
cv2.waitKey(0)
![This is the original image](https://i.stack.imgur.com/w7un6.jpg)
![This is threshed image](https://i.stack.imgur.com/eUkAk.jpg)
![This is convex hulled image on largest contour](https://i.stack.imgur.com/br3Cb.jpg)