首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OpenCV "findContours“方法错误

OpenCV "findContours“方法错误
EN

Stack Overflow用户
提问于 2014-01-16 22:02:17
回答 2查看 4K关注 0票数 0

我对OpenCV 2.4.8的"findContours“方法有异议。具体而言,以下错误:

代码语言:javascript
运行
复制
OpenCV Error: Unsupported format or combination of formats ([Start]FindContours support only 8uC1 and 32sC1 images) in cvStartFindContours, file ..\..\..\..\opencv\modules\imgproc\src\contours.cpp, line 196

从消息的内容来看,我似乎使用了不适当的图像格式,但是我很确定我的代码指定了一个8uC1 (8位1通道)矩阵。

代码语言:javascript
运行
复制
/* Threshold source image (src1 which is a grayscale image) */
Mat threshImg(src1.rows, src1.cols, CV_8UC1);
threshold(src1, threshImg, thresh, 255, CV_THRESH_BINARY);

/* Get contours */
Mat threshCopy = threshImg; // Copying image because findContours method edits image data
std::vector<std::vector<Point>> contours;
findContours(threshCopy, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0,0));

我使用cl和链接在命令行上编译代码,如下所示:

代码语言:javascript
运行
复制
$: cl NameOfCode.cpp -W2 -EHsc -c -I OpenCVIncludeDirectory
$: link NameOfCode.obj -LIBPATH:OpenCVLibraryDirectory opencv_core248.lib opencv_highgui248.lib opencv_imgproc248.lib

为了启用cl和link的使用,我从Visual 2010运行vsvars32.bat:

代码语言:javascript
运行
复制
$: "C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
EN

Stack Overflow用户

回答已采纳

发布于 2014-01-20 15:20:19

看起来这个问题最终与Visual有关。安装SP1 http://www.microsoft.com/en-us/download/details.aspx?id=23691并按照berak和vasan的建议对代码进行调整之后。最后代码如下:

代码语言:javascript
运行
复制
/* NOTE: Using namespace cv & std */

/* Get input image */
Mat origImg = imread("C:\\PathToImage\\Image.png", CV_LOAD_IMAGE_GRAYSCALE);

/* Threshold input image */
Mat threshImg;
threshold(origImg, threshImg, 150, 255.0, THRESH_BINARY);

/* Get contours from threshold image */
Mat copyImage = threshImg.clone();
vector<vector<Point>> contours;
findContours(copyImage, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0,0));
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21173829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档