Skip to main content

Rectify lens distortions with Lensfun and OpenCV

Project description

PhoToRectify

Notice: Only tested for Hasselblad L1D-20c and Pentax K-1 with HD Pentax-D FA 28-105mm f/3.5-5.6 ED DC WR.

Undistort images with the Lensfun library and OpenCV. Multiprocessing is supported to speed up the rectification.

  • Allowed input file formats: BMP, JPEG, JPEG 2000, PNG, PIF, SUN RASTERS, TIFF
  • Output file formats: JPEG, TIFF
  • Currently supported and used compressions:
    • JPEG with Quality 97
    • TIFF with JPEG-Compression
  • Custom meta data (optional arguments, use quotes if they contain spaces)

Installation

Installation into a virtual environment is recommended, because PhoToRectify depends on some other packages.

Install with: pip install photorectify
Update with: pip install --upgrade photorectify

Requirements

  • Python 3.7+

  • exiftool 10.38+ (older versions not tested; install it with your distribution’s package manager)

  • PyExifTool has been modified and is shipped with photorectify’s source code (removed -n optional argument for proper lens detection with Lensfun + added method copy_tags())

  • For development: poetry (do not skip the installation of the development dependencies!)

Alternative remapping method for undistort()

Instead of using Pillow, you can also use OpenCV for remapping.

self.img_bgr_undist = lensfunpy.util.remap(
    self.img_blob_bgr,
    undistorted_coords)

Examples

Rectify one photo in a directory (rectifed photo are stored in the same directory as the input file):
photorectify Sampledata/DJI_0051.JPG

Rectify all photos in a directory:
photorectify Sampledata/

Rectify into a custom output directory:
photorectify Sampledata/ -o Sampledata/Rectified

Append custom suffix to rectified photos (automatically adds an underscore):
photorectify Sampledata/ -s rect

Specify meta data if photo hasn’t any EXIF tags:

photorectify Sampledata/DJI_0051.JPG \
    --model L1D-20c \
    --make Hasselblad \
    --FLength 10.26 \
    --FNumber 4.5

Get version:
photorectify --version

Development

More cameras and lenses can be supported by adding them to lensfun-db.xml. See the Lensfun database.

Running tests:
poetry run pytest -q tests/test_rectification.py

Contribution

To help improving this python package, open an issue or create a merge request.

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

PhoToRectify-1.1.2.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

PhoToRectify-1.1.2-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file PhoToRectify-1.1.2.tar.gz.

File metadata

  • Download URL: PhoToRectify-1.1.2.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.9 Windows/10

File hashes

Hashes for PhoToRectify-1.1.2.tar.gz
Algorithm Hash digest
SHA256 34a46751faee6ce032ca993a0025e6c17d3a84aed664fe2b17783e80bcd3f410
MD5 e10176fba6034d63184f6d70eeac93e8
BLAKE2b-256 592bbf7fcf1eaa5bd202242bde9b6f34213dc6e6cfbecff5f5c4a95c3a4bddbe

See more details on using hashes here.

File details

Details for the file PhoToRectify-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: PhoToRectify-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.9 Windows/10

File hashes

Hashes for PhoToRectify-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d080635428aad21104eb1abc10d4133cabc42f80b7bb652d5bf158c0eec0e594
MD5 6b2fabf0ac77e11a346a5c4cc11608ba
BLAKE2b-256 89d7f38d262ad159a8856f6dd1b6ba79710647d4cc45f35d6f621ad5c93a0919

See more details on using hashes here.

Supported by

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