Inspired by mobile applications like CamScanner, this project implements a document scanner using OpenCV in Python. It includes perspective correction, document boundary detection, and a final enhancement filter called Magic Color that improves readability by increasing contrast and saturation intelligently.
- Edge Detection and Perspective Correction
- Filters and Enhancement
- Real-Time Controls
- Result Examples
The project begins by detecting the document edges in the image and applying perspective correction to flatten the image. This mimics the way scanning apps like CamScanner transform angled shots into clean, readable documents.
Key functions:
- order_points: Sorts the contour points to top-left, top-right, bottom-right, bottom-left.
- four_point_transform: Applies a warp transformation to generate a top-down view of the document.
Once the image is transformed, several filters can be applied:
- Grayscale: Converts image to standard grayscale.
- Black & White: Increases readability using adaptive thresholding.
- Magic Color: Increases brightness, contrast, and sharpness to make documents appear vivid and more like scanned copies.
A simple OpenCV-based UI allows you to:
- Press buttons to apply different filters.
- Press save button to save the currently displayed image.
- Press
qto quit the window.
The UI runs in a while loop until the user chooses to exit, creating a live and interactive experience.
Here’s an example of how the sample image can be enhanced with color magic filter document clarity:
Original Image |
Scanned Output |

