I have the following image as a test image:
I attempt to find the shapes on the image (and other images). My approch right now is the following:
- Gaussian blur with a 3x3 kernel
- Canny edge detection using list (to get all shapes)
- Morphology with MorphOp.Close to close the edges
- FindContours to find contours
- Iteration of each contour:
- Find ApproxPolyDP
- Find ConvexHull
- Discard if hull size < 2, approx area < 200 or hull size > 50000, or arclength of the approx < 100
- Draw convexhull
This method yields the following images where the convex hulls are drawn:
This is almost perfect, but notice that the lines are seen as a contours events->suppliers and events->documents). When looking at the edge information, it becomes apparent why this is so:
The lines are detected as a contour. How could I prepare/find the shapes so the lines are not detected? I though of some thinning algorithm, but since I also work on real life images it is difficult to find a threshold that works. Here is an example of a real life image where thinning is difficult to do because thinning typically requires the images to be monochrome in black and white.
How would you do it? Is there some method to determine if the contour/convex hull is a line, rectangle or something like this?