- it's purpose is to do one thing, and to do it right
- lightweight (no heavy models), fast and super-easy to use
- the code detects pixels that are supposed to be white and makes them white, so that if you need to print the document you don't have to waste ink
- automatically scan all the images in a directory
- choose if you want the result to be colorized or black and white
- Detects the document using OpenCV.
- Applies perspective transformation to align the sheet.
- Cleans up the background.
- Saves the processed document as an A4 PDF
The photo must contain the 4 corners of the sheet (it will obviously work better if there's nothing else in the picture and if the quality is high), and it has to be vertical.
git clone https://github.com/davide710/scanner.git
pip install -r requirements.txt
Command Line | Description |
---|---|
python3 src/main.py path/to/image [-c (colorized)] |
Scans the image provided by the path |
python3 src/main.py path/to/folder [-c (colorized)] |
Scans all images inside the folder provided by the path |
python3 src/main.py . [-c (colorized)] |
Scans all the images within the current directory |
All files generated by the program will be output into the follwing directory:
scanned/{file_name}.pdf
- jpg
- jpeg
- png
- Ensure the path to the file provided is correct
- Try again with an absolute path
- Verify there are valid files within the folder directory provided
- Replace main.py with doc_scan_click.py found within the test_and_others folder
- You will see your document, where you can then manually click the four corners of the sheet
The same code is behind https://onlinescanner.pythonanywhere.com/
I keep uploading many results, trying to show both examples of successful and failed tests and highlight pros and cons of the different ideas I get. If you want to improve this, if you have an idea to make it better, or if you are having trouble using or setting this up, please raise an issue. Otherwise, work on one of the improvements I mentioned in the Issues section. You can also star the repository.
This project is open-source and available under the MIT License.