tags:

views:

64

answers:

0

Hi,

I use pyopencv to find contours but I cannot draw the found contours. I got the error:

 23 color = Scalar(255)
 24 print type(color)

---> 25 drawContours(img, list(contours), -1, color) 26 27 imshow('Xe may - 0', img)

ArgumentError: Python argument types in pyopencv.pyopencvext.drawContours(Mat, list, int, Scalar) did not match C++ signature: drawContours(cv::Mat {lvalue} image, std::vector, std::allocator > >, std::allocator, std::allocator > > > > contours, int contourIdx, cv::Scalar_ color, int thickness=1, int lineType=8, std::vector, std::allocator > > hierarchy=vector_Vec4i(len=0, []), int maxLevel=2147483647, cv::Point_ offset=Point2i(x=0, y=0)) WARNING: Failure executing file:

Here is my code

# load image
img = imread('37S2231.jpg')
# gray scale
out = img.clone()
cvtColor(img, out, CV_RGB2GRAY)
# equalizes the histogram of a grayscale image
# increases the contrast of the image
out2 = out.clone()
equalizeHist(out, out2)
# canny to extract edges
out3 = out2.clone()
Canny(out2, out3, 150, 200)
# threshold
out4 = out3.clone()
threshold(out3, out4, 254, 255, THRESH_BINARY)
# contours
contours = findContours(out4, 1, 1)
print type(contours)
color = Scalar(255)
print type(color)
drawContours(img, list(contours), -1, color)

I have checked the drawContours function at http://packages.python.org/pyopencv/2.1.0.wr1.0.2/ but it looks similar to my code. Did I do something wrong?

Thanks