How can I use the Imgproc.findContours() method only on a certain portion of an image, and not the whole image? [closed]

asked 2017-09-18 13:13:00 -0600

I have an image containing a multitude of shapes. I want to find and count only those shapes that are heptagons. Just to figure out if the shape in the image is a heptagon or not, I find that shape's circularity (using contour area and arc length) in the image, and test to see if it matches within a reasonable margin of the actual circularity value of a heptagon. Therefore, how can I take an image containing a multitude of shapes, and perform the OpenCV Java Imgproc.findContours() method on each of the shapes individually, and not the whole image? I belive it may have something to do with finding the white space between each shape.

Your help is very much appreciated.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-26 06:22:19.070505

Comments

findContours returns a vector of contours. (vector of vector of points) so you'll be able to access contours one by one , filter very mall or very large and then perform your algorithm to decide if shape is a heptagone.

Ziri gravatar imageZiri ( 2017-09-18 19:13:24 -0600 )edit

Thank you, but how am I to know what part of the image each contour corresponds to?

JamieCorkhill gravatar imageJamieCorkhill ( 2017-09-18 19:34:16 -0600 )edit

if you want to process parts of image you'll have to set an ROI . If you want to know contour position in image then you can get contour point coordinates and calculate centroid position . Structural Analysis and Shape Descriptors

Ziri gravatar imageZiri ( 2017-09-18 19:50:15 -0600 )edit

To find a heptagon use Imgproc.convexHull and check length of resulting hull .

Ziri gravatar imageZiri ( 2017-09-18 19:54:02 -0600 )edit

So, does that mean if the convexHull length returns a value of 7 that the image is a heptagon? Also, I am 15 years old and relatively new to OpenCV, so how do I set up an ROI? Thank you.

I greatly appreciate your help.

JamieCorkhill gravatar imageJamieCorkhill ( 2017-09-18 20:03:14 -0600 )edit
1

You can set image ROI in JAVA like this :

Rect  Rect_ROI = new Rect(x, y, Width, height);

Mat Mat_ROI = new Mat(Your_Input_Mat , Rect_ROI );

Yes ,convexHull length is the number of points.

Check documentation for JAVA : link text

Ziri gravatar imageZiri ( 2017-09-19 00:01:29 -0600 )edit

Post your code as well so you can get help.

Ziri gravatar imageZiri ( 2017-09-19 00:09:27 -0600 )edit