I'm trying to get the convex hull of a subset of a contour. I get the subset of the contour by slicing every nth point of the contour. OpenCV's convexHull works fine on the original contour, but throws an error when I try to run it on the subset.
a = contour
step = 5
b = contour[0::step]
a.shape, b.shape, a.dtype, b.dtype, a[0], a[-1], b[0], b[-1]
((1398, 1, 2),
(280, 1, 2),
dtype('int32'),
dtype('int32'),
array([[97, 33]], dtype=int32),
array([[98, 33]], dtype=int32),
array([[97, 33]], dtype=int32),
array([[100, 33]], dtype=int32))
So you can see from the above that their shapes are almost the same, except that b has fewer points, and that their data types are the same, and that neither starts and finishes on the same exact point.
This works: cv2.convexHull(a, returnPoints=False)
This doesn't: cv2.convexHull(b, returnPoints=False)
The error I receive is:
error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\convhull.cpp:143: error: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::convexHull'