The objective of this project is to develop a simple document scanner that automatically detects a document from an image taken at an angle and converts it into a properly aligned, top-down scanned image. The project uses image processing techniques learned in the Spatial Domain module.
- Python
- OpenCV
- NumPy
- Spatial Domain Image Processing
- Gaussian Blur
- Sobel Edge Detection
- Thresholding
- Contour Detection
- Polygon Approximation
- Perspective Transformation
Input Image
│
▼
Read Image
│
▼
Gaussian Blur
│
▼
Sobel Edge Detection
│
▼
Thresholding
│
▼
Find Contours
│
▼
Find Largest 4-Sided Contour
│
▼
Arrange Corner Points
│
▼
Perspective Transform
│
▼
Scanned Document
DocumentScanner/
│
├── scanner.py
├── filters.py
├── input.jpg
├── output/
│ ├── sobel_edges.jpg
│ ├── threshold.jpg
│ ├── detected_document.jpg
│ └── scanned_document.jpg
│
├── requirements.txt
└── README.md
This is the main program of the project. It performs the complete document scanning process, including:
- Reading the input image
- Applying Gaussian Blur
- Detecting edges using the Sobel filter
- Applying thresholding
- Detecting contours
- Finding the document boundary
- Applying perspective transformation
- Saving and displaying the final scanned image
This file contains reusable image filtering functions:
- Gaussian Blur
- Sobel Edge Detection
These functions were reused from the Image Filtering Utility developed in the previous assignment.
Install the required libraries.
pip install -r requirements.txtPlace your document image in the project folder and rename it as:
input.jpg
Run the program.
python scanner.pyThe program generates the following output images inside the output folder:
- sobel_edges.jpg – Edge image generated using the Sobel filter.
- threshold.jpg – Binary image after thresholding.
- detected_document.jpg – Original image with the detected document boundary highlighted.
- scanned_document.jpg – Final aligned and flattened document.
After completing this project, I learned:
- How to preprocess images using Gaussian Blur.
- How the Sobel filter detects edges using image gradients.
- How thresholding converts grayscale images into binary images.
- How contours are used to detect object boundaries.
- How to identify the document using the largest four-sided contour.
- How perspective transformation removes distortion and creates a top-down scanned document.
This project demonstrates the use of spatial domain image processing techniques to build an Intelligent Document Scanner. By combining Gaussian Blur, Sobel Edge Detection, contour detection, and perspective transformation, the system automatically detects and aligns a document from an angled image, producing a clean scanned output suitable for further applications such as OCR and document redaction.