Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

  1. Convert image to grayscale (cvtColor function).
  2. Apply an edge detector (Canny or Sobel, for example) to obtain a binary image (0 on the background, 1 on edges).
  3. 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).
  4. Iterate through this vector to keep only lines with angles similar to 0° or 90° (supposing your page is almost perpendicular to axes).
  5. 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).
  6. 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.