Heni
Heni

Reputation: 156

Contour comparison in opencv

I have create some code in opencv/c++ witch can find contour of an image (leaf) so after getting the contour result from the method

findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

the result of this method will be saved in "contours" type (OutputArrayofArrays)

so the problem is how to compare those result with an other?

I find that this method can compare but i cannot use it!

double compare = cvMatchShapes(R, T, CV_CONTOURS_MATCH_I1);

R,T: 2 objects to compare.

thank you

Upvotes: 0

Views: 2755

Answers (1)

avtomaton
avtomaton

Reputation: 4874

Firstly you should define what do you mean as "other" result.

Secondly, possibly it's better to use cv::matchShapes (C++ interface) instead of cvMatchShapes (C interface) - you will have less problems with types compatibility/conversion.

"contours" type fromcv::findContours is no more than vector<vector<cv::Point>, i. e. there are more than one contour in its output.

cv::matchShapes takes vector<cv::Point> or cv::Mat as input parameters, i. e. you can compare only 2 contours with this function.

Thus you should firstly extract contours which you're interested in (for example, with more than N points, or with more than X total length) from cv::findConntours output, and then compare each contour to other one.

If you're interested in comparison of contours from next cv::findContours call output, you can do this with any matching technique for array elements (for example, brute-force, i. e. each element of previous array with each element of current array).

Some more information can be found in OpenCV documentation: 3.0 version or 2.4 version.

Upvotes: 3

Related Questions