Ask Your Question
2

findContours gives me the border of the image

asked 2012-10-05 04:38:24 -0500

Oscanto gravatar image

updated 2015-08-22 07:36:54 -0500

Hello, I'm working with OpenCv on Android and have a problem with the findContours function because it gives me the border of the image.

Here is an example (source image will always be a thresholded image) :

pic1 pic2

As you can see, I do have the contour of the blob, but I don't want to get the contour of the picture...

Actually, I need to find the biggest blob, so what I do is to find every contour, and then find the one with the biggest area, but to do this, I have to save the biggest area (which will be the contour of the image) and the second biggest (which will be the true biggest blob)... I think it's pretty ugly and a waste...

Is it a normal behaviour ? And Is there a way of getting rid of this ?

EDIT : here is the code i'm using

Mat eyeMat = faceMat.submat(eyesArray[j]); //This is a gray image    
Imgproc.GaussianBlur(eyeMat, eyeMat, new Size(9, 9), 2, 2);    
Imgproc.threshold(eyeMat, eyeMat, 30, 255, Imgproc.THRESH_BINARY);    
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(eyeMat, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_NONE);
edit retag flag offensive close merge delete

Comments

Please, post your code with findContours usage.

Daniil Osokin gravatar imageDaniil Osokin ( 2012-10-05 05:44:27 -0500 )edit

It's Done.

Oscanto gravatar imageOscanto ( 2012-10-05 05:55:28 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
12

answered 2012-10-05 06:39:32 -0500

HugoRune gravatar image

updated 2012-10-05 06:40:10 -0500

I believe findContours treads white as foreground and black as background:

The pointer first_contour is filled by the function. It will contain a pointer to the first outermost contour or NULL if no contours are detected (if the image is completely black)

So for findContours your image is a big white rectangle with a black hole in it.

You could negate the image first; otherwise I think you will have to discard the biggest contour.

edit flag offensive delete link more

Comments

You are completely right ! Thank you very much, it now works well, I just need to invert the threshold operation ! Thank you.

Oscanto gravatar imageOscanto ( 2012-10-05 06:54:07 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-10-05 04:38:24 -0500

Seen: 12,295 times

Last updated: Oct 05 '12