首页 文章

pyopencv drawContours

提问于
浏览
2

我使用pyopencv来查找轮廓但我无法绘制找到的轮廓 . 我收到了错误:

23 color = Scalar(255)
24种印刷类型(颜色)
---> 25 drawContours(img,list(contours), - 1,color)26 27 imshow('Xe may - 0',img)ArgumentError:pyopencv.pyopencvext.drawContours中的Python参数类型(Mat,list,int, Scalar)与C签名不匹配:drawContours(cv :: Mat
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))警告:执行文件失败:

这是我的代码

# 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)

我在http://packages.python.org/pyopencv/2.1.0.wr1.0.2/检查了drawContours函数,但它看起来与我的代码类似 . 我做错什么了吗?

谢谢

1 回答

  • 1

    首先感谢这个例子,它是我发现的唯一一个用来说明pyopencv.findContours用法的例子 . 对于您的问题:使用轮廓[0]而不是列表(轮廓)!所以,将最后一行更改为

    drawContours(img, contours[0], -1, color)
    

相关问题