【问题标题】:Finding connected components using contours error in findContours function在 findContours 函数中使用轮廓错误查找连接的组件
【发布时间】:2014-03-24 03:59:11
【问题描述】:

我正在尝试使用轮廓函数查找连接的组件,但 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&lt;std::vector&lt;cv::Point, std::allocator&lt;cv::Point&gt;&gt;, std::allocator&lt;std::vector&lt;cv::Point, std::allocator&lt;cv::Point&gt;&gt;&gt;&gt;" 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&lt;cv::Vec4i, std::allocator&lt;cv::Vec4i&gt;&gt;" to "CvSeq **" exists c:\users\shahd\documents\visual studio 2010\projects\test_opencv\test_opencv\main.cpp 41

【问题讨论】:

  • 没有看到你的其余代码,这很难,所以我吐了......你的第二个和第三个变量的类型错误
  • 我已经编辑了帖子
  • 您将过时的 c-api 调用与 c++ api 混合在一起。如果您始终坚持使用 c++ api,并且避免使用所有 cvfunctions, CvMat IplImage*,那么您所有的问题都会消失

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


【解决方案1】:

问题是您的图像的数据类型是Mat,它被C++ 类型的openCV 使用。但是您使用的函数是C 类型openCV

所以,不要使用cvThreshold(),而是尝试使用threshold(),就像上面提到的link

【讨论】:

  • threshold() 对我不起作用。你认为我应该将 mat 转换为 iplimage 吗?
  • 只坚持一种格式。使用与C type openCVC++ type openCV 相关的所有内容。如果您在代码的每一步都添加注释会很好,因为我真的无法理解您的意图是什么......例如我不明白你为什么要这样做cvConvert(img, mat);..无论你的@987654328 @ 属于 IplImage*Mat。同样,我也不明白你为什么用Mat*代替thr,你为什么不只用Mat
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
  • 2016-08-11
  • 2017-07-03
相关资源
最近更新 更多