5

After taking a picture with an android phone I want to identify an object in the picture by clicking into it for example. Possible objects in most cases:
1. Ruler
2. Person
3. Pencil
I am using android prebuilt-opencv version 2.3.1 and I tried to click into the ruler object and floodfill it to mark it, but if the contours are not closed the whole picture will be filled.
a) I also tried to click into ruler object and go south, north, east, west to look where the edges are and collect these coordinates, but I ran into heavy problems there (don´t ask).

Questions:
1. Is it possible to close the contours somehow to just fill the wanted object?
2. What I ACTUALLY want to find are the coordinates of the bottom AND the height of (e.g.) the ruler.
ANY other solutions are appreciated. How would you realize it?

Update:I fixed the problem with a) and use this approach at the moment (not happy about it). I also tried Entreco ´s approach, but seem not to give the wanted solution by now.

1 Answer 1

7

I don't know if you tried this, but usually, you can achieve better results by processing the image first.

1) Apply GuassianBlur to remove the noise

2) Apply AdaptiveThreshold -> to convert the image to black and white

3) Apply Dilate operation, to fill the cracks

By using different settings for the AdaptiveThreshold and the Dilate operation, you might be able to get closed contours...

An example I used is like this:

// 1) Apply gaussian blur to remove noise
Imgproc.GaussianBlur(mGraySubmat, mIntermediateMat, new Size(11,11), 0);

// 2) AdaptiveThreshold -> classify as either black or white
Imgproc.adaptiveThreshold(mIntermediateMat, mIntermediateMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 2);

// 3) Invert the image -> so most of the image is black
Core.bitwise_not(mIntermediateMat, mIntermediateMat);

// 4) Dilate -> fill the image using the MORPH_DILATE
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3,3), new Point(1,1));
Imgproc.dilate(mIntermediateMat, mIntermediateMat, kernel);
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot for the answer @Entreco. I will try this and report.
@Entreco can we draw a rectangle arround the closed contours
it is not detect edge if black rectangle object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.