Find distorted rectangle in image (OpenCV)

一个人想着一个人 提交于 2019-12-03 07:24:54
Andrey Sboev

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;
    }
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!