I\'m trying to create a mask from a contour, but am getting a C++ error.
Using OS X Yosemite, Python 2.7.10, OpenCV 3.1.0.
def create_mask(img, cnt):
I think you are adding extra []
around cnt
it should be
cv2.drawContours(mask, cnt, 0, (0, 255, 0), -1)
as cnt
is already array of array but [cnt]
is array of array of arrays which won't work
Update to the above code
you should convert your contour to numpy array first
ctr = numpy.array(cnt).reshape((-1,1,2)).astype(numpy.int32)
cv2.drawContours(mask, [ctr], 0, (0, 255, 0), -1)
check documentation here
contours is a Python list of all the contours in the image. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.