Sunday, 5 February 2017

c++ - opencv: Using contours and Hough transform on rectangle detection

I am trying to detect white rectangles in a grayscale image using different approaches: contour detection and Hough transform. Unfortunately there are some limitations of the image I am processing, i.e.





  1. There are many features in the image and rectangle is not the only features

  2. The rectangle could be merged to other features (e.g. one of the rectangle edges could be overlapped with a long straight line)

  3. The rectangle could contain some other features (e.g. letter, numbers or some logo inside the rectangle)

  4. There are some features look like rectangle (e.g. character 'D' looks like a rectangle with small arc on the top right and bottom right; another example is trapezoid instead of parallelogram)

  5. The rectangle could be rotated from 0 to 15 degrees both clockwise and anti-clockwise

  6. It is possible that the lines are broken into several lines in different lighting condition (e.g. 1 pixel gap) so the minimum line length to filter the lines has to be small (e.g. in Hough Transform)

  7. When the minimum line length is set to small value, it is more often to see duplicate lines for the same line in different orientations (i.e. need to combine several lines)



For the contonours approach, the contours of some images are broken. In addition, the image could contain features like rectangle (e.g. character 'D'). I am not sure if this is a good approach.




I have seen many articles/forum suggesting to use Hough transform to detect rectangle like the following post. Unfortunately I have to set the small value of minimum line length and have seen duplicate lines. I have no idea how to deal with the points mentioned above (e.g. combine all the duplicate lines and pick only one line for each edge, how to differentiate the features with most part are lines but with small arcs like 'D', and how to isolate the square with one edge merged with a long straight line, etc).



Hough transformation vs Contour detection for Rectangle recognition with perspective projection



Any suggestions are welcomed!



EDIT: Add some pictures



Character D




Character D



Rect edge merged with long straight line



Rectangle with logo and the edges are merged with long straight line



enter image description here



Trapezoid (with shadow on the top forming trapezoid in the bottom)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...