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.

Riker
  • 85
  • 6

1 Answers1

4

Correction to the above is -

cv2.polylines(ti, [mask], True, (255,0,0), 1)
I.Newton
  • 1,753
  • 1
  • 10
  • 14
  • 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! – Riker Oct 04 '18 at 17:28
  • the trick is to add `[ ]` around the mask. it works for me – Franva May 02 '21 at 00:23