我使用pyopencv来查找轮廓但我无法绘制找到的轮廓。我收到了错误:
23 color = Scalar(255) 24 print type(color)
---> 25 drawContours(img,list(contours),-1,color) 26 27 imshow('Xe may - 0',img)
ArgumentError:Python参数类型 在 pyopencv.pyopencvext.drawContours(垫, list,int,Scalar)与C ++不匹配 签名: drawContours(cv :: Mat {lvalue}图片, 的std ::向量, std :: allocator> >中 的std ::分配器, std :: allocator> > > > 轮廓,int contourIdx, cv :: Scalar_ color,int thickness = 1,int lineType = 8, 的std ::向量, 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函数,但它看起来与我的代码类似。我做错了吗?
由于
答案 0 :(得分:1)
首先感谢这个例子,它是我发现的唯一一个用来说明pyopencv.findContours用法的例子。对于你的问题:使用轮廓[0]而不是列表(轮廓)!因此,将最后一行更改为
drawContours(img, contours[0], -1, color)