A camera based document scanner using OpenCV
It works with colored images as well
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.x
- OpenCV 3 or later
- Numpy
You can install an unofficial pre-built OpenCV package for Python using pip:
pip install opencv-python
For installing Numpy just run
pip install numpy
You can also build this libraries from the source, but it's easier to use pip
You can use the program to scan a file in a real time video or an image file.
After installing everything, simply open your terminal, navigate to the folder you downloaded "main.py" file and type
python main.py
If you have more than one version of python installed on you computer you may have to specify it
python3 main.py
The process is similar to the video one. You just need to specify the path to the image as an argument to run it.
python main.py -i path/to/the/image.extension
Once the program starts, 2 screens are going to open. One shows the image/video and the other shows 2 trackbars in which you can control the threshold values. These values correspond to the detector's "sensibility"
When a squared object (paper, photo, card, etc..) is detected, some blue dots will appear on the image. This blue dots correspond to the edges of the object. You can adjust those threshold values unitll your region of interest is detected
If you are satisfied with the object detection, you can press 's' to save the region of the image selected or 'esc' to quit. A new folder called 'Scanned' is going to be created (if it doesn't already exists) and your scanned file is going to be saved there
Obs.:
- If your image is too big it may not fit your screen during the scanning, but the saved file is going to be full
- More detailed images work better with this algorithm.