Straighten an image of a page using OpenCV

Akshay Chavan
3 min readMar 14, 2021

This is an application of an article I published a couple of years ago on how to process the output of HoughLines from OpenCV.

I am using the functions from the previous post opencv-hough_lines.py, to get the corners of the page which I will use to straighten a page in an image.

There are 4 snippets of code that will help us get a straighten page:
1. Get an edge detected image
2. Get the corner points using opencv-hough_lines.py
3. Fit a rotated rectangle to edge image to get the straight image dimensions
4. Warp the corner points to an image using the width and height from step 3

This is the image that we will try to straighten.

Original Image

Step 1

Read the input image and use the Canny edge detector to obtain the edge detected image.

--

--