Find distorted rectangle in image (OpenCV)

Dennis Kempin picture Dennis Kempin · Jun 15, 2011 · Viewed 9.5k times · Source

I am looking for the right set of algorithms to solve this image processing problem:

  • I have a distorted binary image containing a distorted rectangle
  • I need to find a good approximation of the 4 corner points of this rectangle

I can calculate the contour using OpenCV, but as the image is distorted it will often contain more than 4 corner points. Is there a good approximation algorithm (preferably using OpenCV operations) to find the rectangle corner points using the binary image or the contour description?

The image looks like this:

enter image description here

Thanks!

Dennis

Answer

Andrey Sboev picture Andrey Sboev · Jun 15, 2011

Use cvApproxPoly function to eliminate number of nodes of your contour, then filter out those contours that have too many nodes or have angles which much differ from 90 degrees. See also similar answer