Ask Your Question
3

findContours gives me the border of the image

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

Oscanto gravatar image

updated 2020-10-28 02:36:50 -0600

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 -0600 )edit

It's Done.

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

1 answer

Sort by ยป oldest newest most voted
13

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

HugoRune gravatar image

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

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 -0600 )edit

Question Tools

Stats

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

Seen: 18,390 times

Last updated: Oct 05 '12