Ask Your Question
0

cv::findContours finds more than one contour

asked 2014-06-05 09:33:33 -0500

Beowulf gravatar image

updated 2014-06-05 10:14:55 -0500

kbarni gravatar image

I'm trying to find contours in an image, but the cv::findContours finds more than one contour.

cv::findContours(image.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

And the result:

1

What I want to find:

2

How can I increase the precision of the cv::findContours in order to find what I want?

Thanks.

edit retag flag offensive close merge delete

Comments

1

Apply Erosion or Morphology Transformations(opening) before findcontour and try again.

Haris gravatar imageHaris ( 2014-06-05 09:59:00 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-06-06 11:26:20 -0500

All that cv::FindContours method does is detect groups of connected pixels, it does not care if two separated blobs actually belong to the same object.

The easiest solution to solve this problem is to apply dilate operations on your image to make sure that the blobs that belong to the same object become connected.

edit flag offensive delete link more

Comments

The real problem with dilate or erosion is that I have a set of different images and once applied dilate or erosion it doesn't work as expected in some other images. - It's a loop that goes inside of a folder scanning all the images inside and apply the effects.

Beowulf gravatar imageBeowulf ( 2014-06-07 18:23:33 -0500 )edit

After you find the contours, you can filter by comparing the current ratio of width/height with the expected ratio w/h of the contours you want.

icedecker gravatar imageicedecker ( 2014-06-11 14:36:24 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-06-05 09:33:33 -0500

Seen: 314 times

Last updated: Jun 06 '14