A Python-based document scanner application that automatically detects document edges, applies perspective transformation, and enhances the document for better readability.
This document scanner uses computer vision techniques to:
- Detect document edges in an image
- Apply perspective transformation to obtain a top-down view
- Enhance document contrast and readability
- Process and save the scanned result
- Python 3.11
- OpenCV (Computer Vision library)
- NumPy (Numerical computing)
- Pillow (Image processing)
- imutils (Image processing utilities)
- scikit-image (Image processing algorithms)
- Clone the repository:
git clone https://github.com/TrishamBP/document-scanner.git cd document-scanner - Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
- Windows:
venv\Scripts\activate
- macOS/Linux:
source venv/bin/activate
- Windows:
- Install the required packages:
pip install -r requirements.txt
- Place the document image you want to scan in the project directory or specify the path when running the program.
- Run the main script:
python scan.py --image path/to/document.jpg
- Optional arguments:
python scan.py --image path/to/document.jpg --output scanned_result.jpg
- The program will:
- Detect document edges
- Apply perspective transformation
- Enhance the document
- Save the processed image
The document scanner follows these key steps:
- Edge Detection: Using Canny edge detection to identify document boundaries.
- Contour Detection: Finding the document contour within the image.
- Perspective Transform: Warping the image to get a top-down view of the document.
- Enhancement: Applying adaptive thresholding and other techniques to improve readability.
📂 Document-Scanner
│-- 📂 examples/ (Sample images before and after scanning)
│-- 📜 scan.py (Main script for document scanning)
│-- 📜 requirements.txt (Dependencies)
│-- 📜 README.md (Project documentation)
| Original Image | Scanned Result |
|---|---|
![]() |
![]() |
This project is licensed under the MIT License - see the LICENSE file for details.
- Add OCR (Optical Character Recognition) functionality
- Implement batch processing for multiple documents
- Create a web interface for easier usage
- Add mobile support through a REST API
- Adrian Rosebrock's PyImageSearch tutorials
- OpenCV documentation and community
- All open-source libraries used in this project

