Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find distorted rectangle in image (OpenCV)

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

like image 455
Dennis Kempin Avatar asked Jun 15 '11 11:06

Dennis Kempin


4 Answers

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

like image 124
Andrey Sboev Avatar answered Nov 14 '22 11:11

Andrey Sboev


little different answer, see

http://opencv.willowgarage.com/documentation/cpp/camera_calibration_and_3d_reconstruction.html

like image 31
plan9assembler Avatar answered Nov 14 '22 11:11

plan9assembler


Look at the opencv function ApproxPoly. It approximates a polygon from a contour.

like image 1
Sammy Avatar answered Nov 14 '22 11:11

Sammy


Try Harris Corner Detector. There is example in OpenCV package. You need to play with params for your image.

And see other OpenCV algorithms: http://www.comp.leeds.ac.uk/vision/opencv/opencvref_cv.html#cv_imgproc_features

like image 1
red1ynx Avatar answered Nov 14 '22 09:11

red1ynx