How can I use the Imgproc.findContours() method only on a certain portion of an image, and not the whole image? [closed]
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.
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.
Thank you, but how am I to know what part of the image each contour corresponds to?
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
To find a heptagon use Imgproc.convexHull and check length of resulting hull .
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.
You can set image ROI in JAVA like this :
Mat Mat_ROI = new Mat(Your_Input_Mat , Rect_ROI );
Yes ,convexHull length is the number of points.
Check documentation for JAVA : link text
Post your code as well so you can get help.