A Python library that converts casual document snapshots into professional-quality scanned documents.
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phototoscan-0.1.4.tar.gz.
File metadata
- Download URL: phototoscan-0.1.4.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9516ee66a493e1fa512dc93f2126ada16973c59ddf3cdcdeca990d4979b44330
|
|
| MD5 |
228036b50c12f072fe1f49c95b7318dc
|
|
| BLAKE2b-256 |
892145695b810843f2d72ee8d4a9d9a737d0910abf37a2f7174708c594a570ce
|
File details
Details for the file phototoscan-0.1.4-py3-none-any.whl.
File metadata
- Download URL: phototoscan-0.1.4-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46c98843605f006744988041f3a5aca500b15a3b8a8ccbe6b55125384c8259cd
|
|
| MD5 |
25681db5170f168b3ca8bebd05fece7f
|
|
| BLAKE2b-256 |
5b2ec6b7f37aac0181f7b7b4b8e42af37d215d1065cb7fa0f6a82c7052759d5c
|