Skip to main content

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, ScanMode
scanner = Scanner()

# Basic usage with file path
result = scanner.scan(
    img_input="path/to/image.jpg",
    output_format=OutputFormat.PATH_STR,
    output_dir="path/to/output",  # optional
    scan_mode=ScanMode.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(
    img_input="path/to/image.jpg",
    output_format=OutputFormat.PATH_STR,
    scan_mode=ScanMode.COLOR  # Use color mode instead of default grayscale
)

# 2. From file path to Path object
path_obj = scanner.scan(
    img_input="path/to/image.jpg",
    output_format=OutputFormat.FILE_PATH
)

# 3. From numpy array to bytes
bytes_data = scanner.scan(
    img_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(
    img_input=image_bytes,
    output_format=OutputFormat.NP_ARRAY
)

Parameters:

  • img_input: Can be a file path (str/Path), bytes/bytearray, or numpy array
  • output_format: Determines the return type (OutputFormat.PATH_STR, OutputFormat.FILE_PATH, OutputFormat.BYTES, or OutputFormat.NP_ARRAY)
  • scan_mode: Optional. Determines the output style (ScanMode.COLOR or ScanMode.GRAYSCALE). Defaults to GRAYSCALE
  • output_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> --scan-mode <MODE>
  • --output-dir is 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.
  • --scan-mode is optional. Can be either color or grayscale (default is grayscale).

Scan all images in a directory

uvx phototoscan --images <IMG_DIR> --output-dir <OUTPUT_DIR> --scan-mode <MODE>
  • The same rules apply for --output-dir and --scan-mode as 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

phototoscan-0.1.3.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

phototoscan-0.1.3-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file phototoscan-0.1.3.tar.gz.

File metadata

  • Download URL: phototoscan-0.1.3.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.5

File hashes

Hashes for phototoscan-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f0d0f1957c510bc8b5bfe35622c6995172923d8aeda4cf0699d1b7b9536e97d5
MD5 3580cf93905224c28f37a0702bf77579
BLAKE2b-256 a100985148606035279af0e5bfd6e3698d5f5f37bba978f82ed9413352175296

See more details on using hashes here.

File details

Details for the file phototoscan-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for phototoscan-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fec06ace347089f83929f4adc938dbb9c260fdd866d360d391a2d3e2df02bb31
MD5 387e0aa6d8deb59669ddb678ec6a238e
BLAKE2b-256 9c3c64e3a6b1c3ae17da026818c08f0ac59821a3f93b2ca2126ce5ef85ae87af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page