0

Several threads report this problem, but all of them show fixing the type of the point list (to int32, i.e. CV_32S) as the solution. The point list below has the appropriate type.

>>> ti = np.zeros((400,400,3), np.uint8) # Test image >>> mask = np.array([[213,60],[333,240],[93,240],[150,120]], np.int32) # Test point list >>> cv2.polylines(ti, mask, True, (255,0,0), 1) *** cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2437: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'cv::polylines' >>> print(mask.dtype, mask.shape) int32 (4, 2) 

I've tried changing the type (I get a different error, complains it's the wrong type) and re-casting it to int32. Can't make it play nice...

fillConvexPoly works fine (which got me what I needed for now), fillPoly exhibits the same problem as above.

1 Answer 1

4

Correction to the above is -

cv2.polylines(ti, [mask], True, (255,0,0), 1) 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! If mask is defined with np.array( [ [ [x1, y1], [x2, y2], [x3, y3] ] ], np.int32 ) it's all good. Not sure why it wants an array of an array of points, or how one would infer that from any of the docs I've seen -- great example of the value of SO!
the trick is to add [ ] around the mask. it works for me

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.