Skip to main content

Perspectra

Software and corresponding workflow to scan documents and books with as little hardware as possible.

Check out github:adius/awesome-scanning for and extensive list of alternative solutions.

Installation

We recommend to use uv instead of pip to install the package.

uv tool install perspectra

To install from source:

git clone https://github.com/ad-si/Perspectra
cd Perspectra
make install

Usage

Command Line Interface

usage: perspectra [-h] [--debug] {binarize,correct,corners,renumber-pages} ...

options:
  -h, --help            show this help message and exit
  --debug               Render debugging view

subcommands:
  subcommands to handle files and correct photos

  {binarize,correct,corners,renumber-pages}
                        additional help
    binarize            Binarize image
    correct             Pespectively correct and crop photos of documents.
    corners             Returns the corners of the document in the image
                        as [top-left, top-right, bottom-right, bottom-left]
    renumber-pages      Renames the images in a directory according to their page numbers.
                        The assumend layout is `cover -> odd pages -> even pages reversed`

Best Practices for Taking the Photos

Your photos should ideally have following properties:

  • Photos with 10 - 20 Mpx
  • Contain 1 document
    • Rectangular
    • Pronounced corners
    • Only black content on white or light-colored paper
    • On dark background
    • Maximum of 30° rotation

Camera Settings

# Rule of thumb is the inverse of your focal length,
# but motion blur is pretty much the worst for readable documents,
# therefore use at least half of it and never less than 1/50.
shutter: 1/50 - 1/200 s

# The whole document must be sharp even if you photograph it from an angle.
# Therefore at least 8 f.
aperture: 8-12 f

# Noise is less bad than motion blur => relative high ISO
# Should be the last thing you set:
# As high as necessary as low as possible
iso: 800-6400

When using Tv (Time Value) or Av (Aperture Value) mode use exposure compensation to set lightness value below 0. You really don't want to overexpose your photos as the bright pages are the first thing that clips.

On the other hand, it doesn't matter if you loose background parts because they are to dark.

Generating the Photos from a Video

A good tool for this purpose is PySceneDetect. It's a Python/OpenCV-based scene detection program, using threshold/content analysis on a given video.

For easy installation you can use the docker image

Find good values for threshold:

docker run \
  --rm \
  --volume (pwd):/video \
  handflucht/pyscenedetect
  --input /video/page-turning.mp4 \
  --downscale-factor 2 \
  --detector content \
  --statsfile page-turning-stats.csv

To launch the image run:

docker run \
  --interactive \
  --tty \
  --volume=(pwd):/video \
  --entrypoint=bash \
  handflucht/pyscenedetect

Then run in the shell:

cd /video
scenedetect \
  --input page-turning.mp4 \
  --downscale-factor 2 \
  --detector content \
  --threshold 3 \
  --min-scene-length 80 \
  --save-images

TODO: The correct way to do this: (after https://github.com/Breakthrough/PySceneDetect/issues/45 is implemented)

docker run \
  --rm \
  --volume (pwd):/video \
  handflucht/pyscenedetect \
  --input /video/page-turning.mp4 \
  --downscale-factor 2 \
  --detector content \
  --threshold 3 \
  --min-scene-length 80 \
  --save-images <TODO: path>

Aim for a low threshold and a long minimun scene length. I.e. turn the page really fast and show it for a long time.

TODO

Metadata

Release files for perspectra 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for perspectra 0.2.1
File Size Uploaded
perspectra-0.2.1.tar.gz 5.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for perspectra 0.2.1
File Interpreter ABI Platform
perspectra-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.5 MB

Release files / perspectra-0.2.1.tar.gz

Download URL perspectra-0.2.1.tar.gz
Size 5.5 MB
Tags Source
SHA-256 checksum
How to use checksums
5776a6fc92f0826d369223a6baa74eb35e40228be81ceee20fa7a6d3c18883a8
BLAKE2b-256 checksum
How to use checksums
6a94ea11bc6fa1dd677da51dea272a0ba2893a941ad0a22691d3c912d88abd36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.2

Release files / perspectra-0.2.1-py3-none-any.whl

Download URL perspectra-0.2.1-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b86c1511c18d25d9f796664cbcd35871be51beb9283ee23a242eacb672baff6b
BLAKE2b-256 checksum
How to use checksums
2cd7731a6fb8f1926e9d04ad0da701b3954eff1ade020b9f7f3f3a754192b745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.2

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page