PhotoToScan
A Python library that converts casual document snapshots into professional-quality scanned documents.
This project makes use of the OpenCV-Document-Scanner from @andrewdcampbell and @joaofauvel, and the transform and imutils modules from @PyImageSearch (which can be accessed here).
Environment
uv - An extremely fast Python package and project manager, written in Rust.
Installation
pip install phototoscan
How To Use It
As a library
Examples
from phototoscan import OutputFormat, Mode, Photo
# Basic usage with file path
photo = Photo(
img_input="path/to/image.jpg",
output_format=OutputFormat.PATH_STR,
output_dir="path/to/output", # optional
mode=Mode.COLOR # optional, defaults to COLOR
)
result = photo.scan()
# Advanced usage with various input and output types
# 1. From file path to file path string
photo = Photo(
img_input="path/to/image.jpg",
output_format=OutputFormat.PATH_STR,
mode=Mode.GRAYSCALE # Use grayscale mode instead of default color
)
path_str = photo.scan()
# 2. From file path to Path object
photo = Photo(
img_input="path/to/image.jpg",
output_format=OutputFormat.FILE_PATH
)
path_obj = photo.scan()
# 3. From numpy array to bytes
photo = Photo(
img_input=numpy_array,
output_format=OutputFormat.BYTES,
ext=".jpg" # required when input is numpy array and output is bytes
)
bytes_data = photo.scan()
# 4. From bytes to numpy array
photo = Photo(
img_input=image_bytes,
output_format=OutputFormat.NP_ARRAY
)
np_array = photo.scan()
Parameters:
img_input: Can be a file path (str/Path), bytes/bytearray, or numpy arrayoutput_format: Determines the return type (OutputFormat.PATH_STR, OutputFormat.FILE_PATH, OutputFormat.BYTES, or OutputFormat.NP_ARRAY)mode: Optional. Determines the output style (Mode.COLOR or Mode.GRAYSCALE). Defaults to COLORoutput_dir: Optional. Directory to save the output (required for file outputs when input is numpy array)output_filename: Optional. Name for the output file (required for file outputs when input isn't a file path)ext: Optional. File extension for output (required for bytes output when input is numpy array)
Notes:
- When providing a file path as input and not specifying an output directory, a folder named "output" will be created at the same level as the input image.
- Any specified output directory that doesn't exist will be created automatically.
- The
scan()method executes the full document scanning workflow:- Load the image from the input source
- Detect document corners
- Apply perspective transformation for a top-down view
- Convert to the specified color mode
- Enhance document quality and readability
- Save or return the processed document
As a command-line tool
To scan a single image:
uvx phototoscan --image <IMG_PATH> --output-dir <OUTPUT_DIR> --mode <MODE>
-
--output-diris optional.- If not provided, a directory named output will be created next to the image file.
- If the specified directory does not exist, it will be created automatically.
-
--modeis optional. Can be eithercolororgrayscale(default iscolor).
Scan all images in a directory
uvx phototoscan --images <IMG_DIR> --output-dir <OUTPUT_DIR> --mode <MODE>
- The same rules apply for
--output-dirand--modeas above.
Metadata
Release files for phototoscan 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phototoscan-0.1.5.tar.gz | 17.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phototoscan-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.4 kB
Release files / phototoscan-0.1.5.tar.gz
| Download URL | phototoscan-0.1.5.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b8a7fa549404cfacb6d2742b6a55841a3e273344718705c4e0cb88c5171bde9
|
|
BLAKE2b-256 checksum How to use checksums |
817307e08061d4b26dd9b6976a064ad895b767d9698b5e36e3c1872e91606681
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / phototoscan-0.1.5-py3-none-any.whl
| Download URL | phototoscan-0.1.5-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37b0afa7aff7365b6d3411af9fe7f0413ab69e70d65935031dd2751aa62ce923
|
|
BLAKE2b-256 checksum How to use checksums |
8089774aff53d3678dc1abe8d24240fb77ad1e9b3b74ead2b2cd94f2be399627
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|