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

有帮助吗?

解决方案

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

其他提示

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

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

I would try generalised Hough Transform it is a bit slow but deals well with distorted/incomplete shapes.

http://en.wikipedia.org/wiki/Hough_transform

  1. This will work even if you start with some defects, i.e. your approxPolly call returns pent/hexagons. It will reduce any contour, transContours in example, to a quad, or whatever poly you wish.
  2. vector<Point> cardPoly;// Quad storage
    int PolyLines = 0;//PolyPoly counter ;)
    double simplicity = 0.5;//Increment of adjustment, lower numbers may be more precise vs. high numbers being faster to cycle.
    while(PolyLines != 4)//Adjust this 
    {
        approxPolyDP(transContours, Poly, simplicity, true);
        PolyLines = Poly.size();
        simplicity += 0.5;
    }
    
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top