cv2.error: OpenCV(4.5.2) /tmp/pip-req-build-13uokl4r/opencv/modules/imgproc/src/convhull.cpp:143: error: (-215:Assertion failed) total >= 0 && (depth == CV_32F || depth == CV_32S) in function 'convexHull' code example

Example: cv2.error: OpenCV(4.3.0) /io/opencv/modules/imgproc/src/drawing.cpp:2374: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'fillPoly'

new_img = cv2.fillPoly(blank_img,[cnt],color =(255,255,255))

I was facing error in this line.

so The solution is make sure "cnt" must be int not float.

CHANGES:
cnt = np.array([[50,50], [50,150], [150,150], [150,50]],dtype=np.int32)

Tags:

Misc Example