I'm trying to draw an arbitrary quadrilateral over an image using the polylines function in opencv. When I do I get the following error
OpenCV Error: Assertion failed (p.checkVector(2, CV_32S) >= 0) in polylines, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/d rawing.cpp, line 2065
I call the function as like so,
cv2.polylines(img, points, 1, (255,255,255))
Where points is as numpy array as shown below (The image size is 1280x960):
[[910 641]
[206 632]
[696 488]
[458 485]]
and img is just a normal image that I'm able to imshow. Currently I'm just drawing lines between these points myself, but I'm looking for a more elegant solution.
How should I correct this error?
The problem in my case was that
numpy.array
createdint64
-bit numbers by default. So I had to explicitly convert it toint32
:(Looks like a bug in cv2 python binding, it should've verified
dtype
)The official documentation to provide explanation,need reshape
the error says your array should be of dimension 2. So reshape the array as follows:
Then it works fine.
Also, answer provided by jabaldonedo also works fine for me.
This function is not enough well documented and the error are also not very useful. In any case,
cv2.polylines
expects a list of points, just change your line to this:The example above will print the following image (rescaled):