Hello everyone, here’s the deal. I’m trying to count the number of shapes visible in an image, the shapes can only be triangles or circles (I think this point will help on the counting at the end).
Here is the current state of my program in image, the steps go in order from left to right, top to bottom.
- Original image
- Blurred image to take out the noise the best I can. The blur used is a GaussianBlur with a [7,11] kernel as it seemed to provide better results when the longer side was following the background lines.
- I recreate a background “guess” by taking the trimmed average (removing 10% lowest and 10% highest values)
- I create a diff between picture 2 and 3
- Apply a threshold to remove most of the noise artifacts
- Turn the image into grayscale and threshold again to have a binary
- Get all contours
- Remove contours of shapes with small area
- Reduce the amount of edges using approxPolyDP
Please note that after step 6, I compare the number of white pixels vs black ones. Whites should account for less than 40% of the image, if not this means the isolation did not work correctly because the background lines are vertical instead of horizontal so I redo steps 1 to 6 with everything rotated 90degrees.
This is the result of a long trial and error process, as I do not really know what I am doing nor what tools are at my disposal here…
The next challenge I have concerns cut shapes like on the image above, and overlapping shapes. I need to figure a way to join this triangle so I can count the number of contours that I have to know the amount of shapes.
As for the overlapping shapes. I thought about incrementing count by 1 for each convex shape and by 2 for concave ones, but 3 shapes can overlap, and the current contours I have are creating concave shapes even for a simple triangle here.
Would you have any suggestions on how I could better create the binary image for shape detections? Or how would you go from here to counting the shapes?
Thank you in advance.