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 Scanner, OutputFormat, ScanningMode
scanner = Scanner()
# Basic usage with file path
result = scanner.scan(
image_input="path/to/image.jpg",
output_format=OutputFormat.PATH_STR,
output_dir="path/to/output", # optional
scanning_mode=ScanningMode.GRAYSCALE # optional, defaults to GRAYSCALE
)
# Advanced usage with various input and output types
# 1. From file path to file path string
path_str = scanner.scan(
image_input="path/to/image.jpg",
output_format=OutputFormat.PATH_STR,
scanning_mode=ScanningMode.COLOR # Use color mode instead of default grayscale
)
# 2. From file path to Path object
path_obj = scanner.scan(
image_input="path/to/image.jpg",
output_format=OutputFormat.FILE_PATH
)
# 3. From numpy array to bytes
bytes_data = scanner.scan(
image_input=numpy_array,
output_format=OutputFormat.BYTES,
ext=".jpg" # required when input is numpy array and output is bytes
)
# 4. From bytes to numpy array
np_array = scanner.scan(
image_input=image_bytes,
output_format=OutputFormat.NP_ARRAY
)
Parameters:
image_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)scanning_mode: Optional. Determines the output style (ScanningMode.COLOR or ScanningMode.GRAYSCALE). Defaults to GRAYSCALEoutput_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.
As a command-line tool
To scan a single image:
uvx phototoscan --image <IMG_PATH> --output-dir <OUTPUT_DIR> --scanning-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.
-
--scanning-modeis optional. Can be eithercolororgrayscale(default isgrayscale).
Scan all images in a directory
uvx phototoscan --images <IMG_DIR> --output-dir <OUTPUT_DIR> --scanning-mode <MODE>
- The same rules apply for
--output-dirand--scanning-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.2.tar.gz.
File metadata
- Download URL: phototoscan-0.1.2.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f0ff93da88b88985b89c00fa862efde389556d87a0432c974ca1d9b5816bdc9
|
|
| MD5 |
804a535b98cbfd4e0ce4510286435852
|
|
| BLAKE2b-256 |
4f3f17e377ffdab1eac8e5d447d299d7611cd3e6726b0822b155314186a369cc
|
File details
Details for the file phototoscan-0.1.2-py3-none-any.whl.
File metadata
- Download URL: phototoscan-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5ad5a2253b7cd4b87892984be98844e66117c2638fcf81060d180b4780f3efd
|
|
| MD5 |
c6582ce0c0f9972674a8bb9fff29500b
|
|
| BLAKE2b-256 |
d3196e327ba196a5eea63d99f692895af73ecba32bebe92a9cbfa547c172a076
|