Damilola
Damilola

Reputation: 1024

OpenCV findContour : no matching function

I am trying to use Hough lines in a particular scenario and keep getting no matching function error for findContours method

code

...
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

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&}’

Kindly assist, I am not sure what I am missing here.

Environment: OpenCV 2.4.6.1; Eclipse CDT, Ubuntu 12.04.2

Upvotes: 1

Views: 3948

Answers (2)

Ben Lings
Ben Lings

Reputation: 29443

I think the problem here is that Mat::clone() returns a temporary and you can't get a reference to a temporary. The constructor for _OutputArray takes a Mat&. Assigning it to a variable first will work (as you show in your answer).

Upvotes: 0

Damilola
Damilola

Reputation: 1024

I got through by replacing

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

with

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

It's a bit weird though, given that the definition of findContour has first argument to be of type InputOutputArray which maps to type Map, and the clone method also return type Mat.

Upvotes: 1

Related Questions