This forum is disabled, please visit https://forum.opencv.org

1 | initial version |

Hi, it is not so difficult, the basic steps are the following:

- Convert image to grayscale (
*cvtColor*function). - Apply an edge detector (
*Canny*or*Sobel*, for example) to obtain a binary image (0 on the background, 1 on edges). - Run the
**Probabilistic Hough Line Transform**(better suited for finding few long lines) with the*HoughLinesP*function to obtain a vector of lines (you have to tweak the parameters to accomodate your scenario). - Iterate through this vector to keep only lines with angles similar to 0° or 90° (supposing your page is almost perpendicular to axes).
- For each pair of lines with perpendicular angles, find the intersection point (here is better to solve the equivalent system of line equations for more robustness).
- You have a bunch of points for each of the four page corners, you must run a distance threshold filtering to merge them to obtain at most 4 of them.

Two excellent tutorials for the first three steps are part of the OpenCV documentation and you can find here and here.

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.