I'm trying to detect white rectangles in an image in shades of gray, using different approaches: defining a path and Hough transform. Unfortunately, there are some limitations to the image I process, i.e.
- There are many functions in an image, and a rectangle is not the only functions.
- The rectangle can be combined with other functions (for example, one of the edges of the rectangle can be overlapped by a long straight line)
- The rectangle may contain some other functions (for example, a letter, numbers, or some logo inside the rectangle).
- Some functions look like a rectangle (for example, the βDβ symbol looks like a rectangle with a small arc in the upper right and lower right corner, another example is a trapezoid instead of a parallelogram)
- The rectangle can be rotated from 0 to 15 degrees both clockwise and counterclockwise
- It is possible that the lines are divided into several lines in different lighting conditions (for example, 1 pixel gap), so the minimum line length for filtering lines should be small (for example, in the Hough transform).
- When the minimum line length is set to a small value, most often you need to see repeating lines for the same line in different orientations (i.e. you need to combine several lines)
For the contonours approach, the contours of some images are broken. In addition, the image may contain functions such as a rectangle (for example, the symbol "D"). I am not sure if this is a good approach.
I have seen many articles / forums suggesting using the Hough transform to detect a rectangle similar to the following post. Unfortunately, I have to set a small value for the minimum line length and see duplicate lines. I have no idea how to deal with the points mentioned above (for example, combine all repeating lines and select only one line for each edge, how to distinguish functions with most of them - these are lines, but with small arcs such as "D", and how isolate a square with one edge combined with a long line, etc.).
Hough vs Contour transform for perspective rectangle recognition
Any suggestions are welcome!
EDIT: add some pictures

D symbol

Rectangle with logo and edges combined with a long straight line

Trapezoid (with a shadow on the upper forming trapezoid below)
source share