【问题标题】:OpenCV findContour : no matching functionOpenCV findContour:没有匹配功能
【发布时间】:2013-10-16 22:54:35
【问题描述】:

我正在尝试在特定场景中使用霍夫线,但 findContours 方法一直没有匹配的函数错误

代码

...
Mat bw, hsvdst;
...
bw = Mat::zeros(hsvdst.rows, hsvdst.cols, CV_8UC1);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(bw.clone(), contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

错误

error: no matching function for call to ‘findContours(cv::Mat, st
d::vector<std::vector<cv::Point_<int> > >&, std::vector<cv::Vec<int, 4> >&, cv::<anonymous enum>, cv::<anonymous enum>)

note: candidates are:
void cv::findContours(cv::InputOutputArray, cv::OutputArrayOfArr
ays, cv::OutputArray, int, int, cv::Point)
note:   no known conversion for argument 1 from ‘cv::Mat’ to ‘cv::Inpu
tOutputArray {aka const cv::_OutputArray&}’

请协助,我不确定我在这里缺少什么。

环境:OpenCV 2.4.6.1; Eclipse CDT,Ubuntu 12.04.2

【问题讨论】:

  • 编译器可以很好地告诉您确切的问题是什么。 note: no known conversion for argument 1 from ‘cv::Mat’ to ‘cv::Inpu tOutputArray {aka const cv::_OutputArray&amp;}’
  • 我的想法是 OutputArray 映射到 Mat 类型。我需要显式转换吗

标签: c++ opencv contour


【解决方案1】:

我通过替换解决了

findContours(bw.clone(), contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

Mat m = bw.clone(); findContours(m, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

这有点奇怪,因为 findContour 的 definition 的第一个参数是 InputOutputArray 类型,映射到 Map 类型,并且 clone 方法也返回类型 Mat。

【讨论】:

    【解决方案2】:

    我认为这里的问题是Mat::clone() 返回一个临时文件,而您无法获得对临时文件的引用。 _OutputArray 的构造函数采用 Mat&amp;。首先将其分配给变量将起作用(如您在答案中所示)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-14
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      相关资源
      最近更新 更多