Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pyopencv等高线_Opencv - Fatal编程技术网

pyopencv等高线

pyopencv等高线,opencv,Opencv,我使用pyopencv查找轮廓,但无法绘制找到的轮廓。我得到了一个错误: --->25图纸轮廓(img,列表(轮廓),-1,颜色) 26 27 imshow('Xe五月-0',img) ArgumentError:Python参数类型 在里面 pyopencv.pyopencvext.drawContours(垫、, 列表,int,标量)与C++不匹配 签名: 绘制等高线(cv::Mat{lvalue}图像, 向量, std::分配器>>, 分配器, std::分配器>>> 轮廓线, cv::标

我使用pyopencv查找轮廓,但无法绘制找到的轮廓。我得到了一个错误:

--->25图纸轮廓(img,列表(轮廓),-1,颜色) 26 27 imshow('Xe五月-0',img)

ArgumentError:Python参数类型 在里面 pyopencv.pyopencvext.drawContours(垫、, 列表,int,标量)与C++不匹配 签名: 绘制等高线(cv::Mat{lvalue}图像, 向量, std::分配器>>, 分配器, std::分配器>>> 轮廓线, cv::标量颜色,int 厚度=1,内部线型=8, 向量, std::分配器>> 层次结构=vector\u Vec4i(len=0,[]),int maxLevel=2147483647,cv::Point_ 偏移量=点2i(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)
我已经在上检查了drawContours函数,但它看起来与我的代码类似。我做错什么了吗


谢谢

首先感谢这个示例,它是我找到的唯一一个演示pyopencv.findContours用法的示例。解决您的问题:使用轮廓[0]而不是列表(轮廓)!因此,将最后一行更改为

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

对于OpenCV 3.x和4.0,在这种情况下,轮廓是一个元组,因为findContours返回三个参数:findContours(图像、模式、方法[、轮廓[、层次[、偏移]])->image、轮廓、层次,因为轮廓不是第一个返回的参数,而是第二个:drawContours(img、轮廓[1]、-1、颜色)
drawContours(img, contours[0], -1, color)