在findContours函数中使用轮廓错误查找连接的组件

时间:2014-02-22 13:06:28

标签: visual-studio-2010 opencv image-processing

我正在尝试使用轮廓函数找到连接的组件,但我收到了findContours函数的错误。我正在使用opencv 2.4.7和visual studio 2010

    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

1 个答案:

答案 0 :(得分:0)

问题是图像的数据类型为Mat,由 C ++类型的openCV 使用。但您使用的功能是 C类型openCV

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