A pure Python document scanner using only NumPy, Numba (to speed up execution) developed from scratch for academic purposes.
| CI/CD | Python | License | 
|---|---|---|
This project is a document scanner built from scratch in Python.
It was developed as part of my TIPE (Personal Initiative Project) in engineering school. The goal was to build a project entirely by ourself, without relying on high-level libraries. This approach allowed me to deeply understand the underlying algorithms—from edge detection to perspective correction—and implement them step by step. It's a testament to learning by doing and the value of reinventing the wheel for educational purposes.
Goal: Archieve an automatic scan of a document. Document will be straightened and binarized in dark and white.
| Feature | Description | 
|---|---|
| Corner Detection | Canny Edge detection | 
| Perspective Correction | Homographic transformation to straighten the document | 
| Binarization | Convert to black and white using local thresholding | 
| Export | Save as PNG (matplotlib) | 
- Python 3.8+
 - Jupyter Notebook
 - Matplotlib
 - NumPy
 - Pil (import image only)
 - Numba (optional)
 
git clone https://github.com/TooLoss/PythonDocumentScanFromScratch.git
cd PythonDocumentScanFromScratch
pip install -r requirements.txtEvery steps are details in the main notebook.
- Sobel filters to detect edges.
 - Hadamar product and Connected Component Labeling to find corners.
 
- Calculate homographic transformation using the detected corners.
 - Apply transformation and fill unaffected values with a nearest neighbors algorithm.
 
- Local tresholding implementation : Sauvola and Niblack.
 
This project includes Jupyter Notebooks for exploration and results visualization:
| Notebook | Description | 
|---|---|
main.ipynb | 
Automatic scan process. | 
/notebook/OptimisationSortie.ipynb | 
How to optimize the size of the projected document. | 
| Other notebooks have to be cleaned up. | 
The process works best if it's a black and white text document. With a high contrast between the page and the background.
| Metric | Value | 
|---|---|
| Detection Accuracy (with default parameters) | Testing ... | 
| Execution Time : Projective transofrm | 12s per image | 
| Execution Time : Tresholding | 1m per image | 
Contributions are welcome! Open an Issue or a Pull Request to suggest improvements.
This project is licensed under the MIT License. See LICENSE for details.
FILIPPO BERGAMASCO : Computer Vision : Projective geometry and 2D transformations / Projective Transform
DJEMEL ZIOU : La détection de contours dans des images à niveaux de gris : mise en œuvre et sélection de détecteurs / Edge detection
L. JAGANNATHAN ; C. V. JAWAHAR : Perspective Correction Methods for Camera- Based Document Analysis / Homography Matrix
Bilèle EL HADDADI
© 2025 – Project developed as part of the TIPE.
