OpenCV || matchShapes findContours assertion failed
-
28-10-2019 - |
Question
I am trying to match two contours with the matchShapes method but I always get assertion failed. I know this must have something to do with the wrong Mat format but I can't seem to be able to solve it.
The findContours is working very well:
vector<vector<cv::Point> > contours;
cv::findContours(incomingimage,
contours,
CV_RETR_EXTERNAL,
CV_CHAIN_APPROX_SIMPLE);
vector<vector<cv::Point> > contourstwo;
cv::findContours(incomingimagetwo,
contourstwo,
CV_RETR_EXTERNAL,
CV_CHAIN_APPROX_SIMPLE);
I get good output from these methods but then
matchShapes(Mat(contours), Mat(contourstwo), CV_CONTOURS_MATCH_I3, 0);
returns
OpenCV Error: Assertion failed
I am a bit in the dark here. Any help would be highly appreciated.
Thank you very much.
Solution
I'm also beginner at openCV, but I just figure out how to solve this today (after many trial and error). Please try this one
matchShapes(contours[0], contourstwo[0], CV_CONTOURS_MATCH_I3, 0);
OTHER TIPS
The input to matchShapes
according to the documentation should be of the type vector<Point>
and not vector<vector<Point> >
, as is the output of findContours
, just iterate over each contour and pass it to matchShapes
.