Thursday 13 June 2019

image processing - Hough transformation vs Contour detection for Rectangle recognition with perspective projection



I made rectangle detection work with contour detection and apply polygon with OpenCv to get location of the rectangle before adjusting the perspective projection. And it's working great. But some people in my group suggested Hough transformation instead. I wonder if there is any advantage of using Hough transformation for rectangle detection.



Update: I tried both of the methods. In my example, both methods worked fine after Canny edge detection. But since Hough transformation produces lines, we have to assume several things such as length of lines and connectability of the lines and should do additional computations such as searching connected lines and find corner points from the connected lines. Personally, I liked contour method better since its concept is simpler. With the method, you just search contours that can be approximated with closed and convex polygons with 4 corners and adjust the polygons for their perspective projections. That's about it.


Answer



What sort of results are you getting with contour detection so far? Got any examples?




Hough transform should work well for rectangle detection IFF you can assume that the sides of the rectangle are the most prominent lines in your image.
Then you can simply detect the 4 biggest peaks in hough space and you got your rectangle.



This works for example with a photo of a white sheet of paper in front of a dark background.



Ideally you would preprocess the image with blur, threshold, morphological operators to remove any small-scale structures before hough transform.



If there are multiple smaller rectangles or other sorts of prominent lines in your images, contour detection might be the better choice.




Some general advantages for the hough transform off the top of my head:




  • Hough transform can still work if part of the rectangle is obstructed or out of the frame.

  • Hough transform should be faster than contour detection, I guess?

  • Hough transform will ignore anything that is not a straight line, so you may have greater success with cluttered images. (if the rectangle sides are the most prominent lines)



In the end it probably depends on the input data. Got any examples?




Perhaps a combined approach would be best? see
Combining Hough Transform and Contour Algorithm for detecting Vehicles License-Plates



I did some experiments in using hough transform to detect rectangles a while back, you can see some preliminary results here:
http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=14491&start=9



Unfortunately that is all that exists at the moment, the project is currently on hiatus, eventually I hope to resume it when I am less busy.



I'd be very interested in your results in comparison.




(If you are doing perspective correction, also check out proportions of a perspective-deformed rectangle )


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...