2014-02-22 27 views
0

我试图找到使用轮廓函数的连接组件,但是我发现findContours函数有错误。我使用OpenCV的2.4.7和Visual Studio 2010在findContours函数中使用轮廓错误查找连接组件

CvMat *mat = cvCreateMat(img->height,img->width,CV_32FC3); 
    cvConvert(img, mat); 
    CvMat *thr = cvCreateMat(img->height,img->width,CV_32FC3); 
    cvCvtColor(mat,thr ,CV_RGBA2RGB); 
    cvThreshold(thr, thr,25, 255,CV_THRESH_BINARY); //Threshold the gray 
    int largest_area=0; 
    int largest_contour_index=0; 
    Rect bounding_rect; 
    vector<vector<Point>> contours; // Vector for storing contour 
    vector<Vec4i> hierarchy; 
    findContours(thr, contours, hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);   //Find the contours in the image 

错误:

IntelliSense: no suitable conversion function from "std::vector<std::vector<cv::Point, std::allocator<cv::Point>>, std::allocator<std::vector<cv::Point, std::allocator<cv::Point>>>>" to "CvMemStorage *" exists c:\users\shahd\documents\visual studio 2010\projects\test_opencv\test_opencv\main.cpp 41

IntelliSense: no suitable conversion function from "std::vector<cv::Vec4i, std::allocator<cv::Vec4i>>" to "CvSeq **" exists c:\users\shahd\documents\visual studio 2010\projects\test_opencv\test_opencv\main.cpp 41

+0

没有看到你的代码的其余部分,这是困难的这样的IM spitballing ... 你的第二个和第三个变量是错误的类型 – GPPK

+0

我已经编辑 – user3108024

+3

你混合过时C-API与C调用的帖子++ API。你所有的问题都会消失,如果你始终坚持使用C++ api,并且避免所有的cv *函数,那么CvMat * IplImage * – berak

回答

0

的问题是,你的形象的数据类型为Mat这是通过使用C++类型的openCV。但是您使用的功能是C型openCV

因此,不要使用cvThreshold(),请尝试使用threshold(),如link所述。

+0

threshold()对我来说并不适用。你认为我应该将垫子转换成iplimage吗? – user3108024

+0

只需坚持一种格式。要么使用所有与“C类型openCV”或“C++类型openCV”有关的东西。如果你在代码的每一步都发表评论会很好,因为我真的无法理解你的意图是什么......例如我不明白你为什么要做'cvConvert(img,mat);' ..你的'img'是'IplImage *'还是'Mat'。同样,我也不明白你为什么使用'mat *'作为'thr',为什么不使用'Mat'? – skm