Skip to main content

Lens distortion correction for Python, a wrapper for lensfun

Project description

lensfunpy is an easy-to-use Python wrapper for the lensfun library.

API Documentation

Sample code

How to find cameras and lenses:

import lensfunpy

cam_maker = 'NIKON CORPORATION'
cam_model = 'NIKON D3S'
lens_maker = 'Nikon'
lens_model = 'Nikkor 28mm f/2.8D AF'

db = lensfunpy.Database()
cam = db.find_cameras(cam_maker, cam_model)[0]
lens = db.find_lenses(cam, lens_maker, lens_model)[0]

print(cam)
# Camera(Maker: NIKON CORPORATION; Model: NIKON D3S; Variant: ;
#        Mount: Nikon F AF; Crop Factor: 1.0; Score: 0)

print(lens)
# Lens(Maker: Nikon; Model: Nikkor 28mm f/2.8D AF; Type: RECTILINEAR;
#      Focal: 28.0-28.0; Aperture: 2.79999995232-2.79999995232;
#      Crop factor: 1.0; Score: 110)

How to correct lens distortion:

import cv2 # OpenCV library

focal_length = 28.0
aperture = 1.4
distance = 10
image_path = '/path/to/image.tiff'
undistorted_image_path = '/path/to/image_undist.tiff'

im = cv2.imread(image_path)
height, width = im.shape[0], im.shape[1]

mod = lensfunpy.Modifier(lens, cam.crop_factor, width, height)
mod.initialize(focal_length, aperture, distance)

undist_coords = mod.apply_geometry_distortion()
im_undistorted = cv2.remap(im, undist_coords, None, cv2.INTER_LANCZOS4)
cv2.imwrite(undistorted_image_path, im_undistorted)

It is also possible to apply the correction via SciPy instead of OpenCV. The lensfunpy.util module contains convenience functions for RGB images which handle both OpenCV and SciPy.

Installation

Binary wheels for Linux, macOS, and Windows are provided for Python 3.5 - 3.8. These can be installed with a simple pip install lensfunpy. Currently, Linux and macOS wheels are only available as 64 bit versions.

Installation from source on Linux/macOS

If you have the need to use a specific lensfun version or you can’t use the provided binary wheels then follow the steps in this section to build lensfunpy from source.

First, install the lensfun library on your system.

On Ubuntu, you can get (an outdated) version with:

sudo apt-get install liblensfun-dev

Or install the latest developer version from the Git repository:

git clone https://github.com/lensfun/lensfun
cd lensfun
cmake .
sudo make install

After that, install lensfunpy using:

git clone https://github.com/letmaik/lensfunpy
cd lensfunpy
pip install numpy cython
pip install .

On Linux, if you get the error “ImportError: liblensfun.so.0: cannot open shared object file: No such file or directory” when trying to use lensfunpy, then do the following:

echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/99local.conf
sudo ldconfig

The lensfun library is installed in /usr/local/lib when compiled from source, and apparently this folder is not searched for libraries by default in some Linux distributions. Note that on some systems the installation path may be slightly different, such as /usr/local/lib/x86_64-linux-gnu or /usr/local/lib64.

NumPy Dependency

lensfunpy depends on NumPy. The minimum supported NumPy version depends on your Python version:

Python

numpy

3.5

>= 1.9

3.6

>= 1.11

3.7

>= 1.14

3.8

>= 1.17

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

lensfunpy-1.7.0-cp38-cp38-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.8Windows x86-64

lensfunpy-1.7.0-cp38-cp38-manylinux2010_x86_64.whl (756.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

lensfunpy-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl (951.4 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

lensfunpy-1.7.0-cp37-cp37m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.7mWindows x86-64

lensfunpy-1.7.0-cp37-cp37m-manylinux2010_x86_64.whl (687.5 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

lensfunpy-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl (949.3 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

lensfunpy-1.7.0-cp36-cp36m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.6mWindows x86-64

lensfunpy-1.7.0-cp36-cp36m-manylinux2010_x86_64.whl (688.9 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

lensfunpy-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl (952.0 kB view details)

Uploaded CPython 3.6mmacOS 10.9+ x86-64

lensfunpy-1.7.0-cp35-cp35m-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.5mWindows x86-64

lensfunpy-1.7.0-cp35-cp35m-manylinux2010_x86_64.whl (679.0 kB view details)

Uploaded CPython 3.5mmanylinux: glibc 2.12+ x86-64

lensfunpy-1.7.0-cp35-cp35m-macosx_10_9_intel.whl (945.3 kB view details)

Uploaded CPython 3.5mmacOS 10.9+ Intel (x86-64, i386)

File details

Details for the file lensfunpy-1.7.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 41dd019875b10aae5ca45cbbf9175eeae2c1b06702bb74c9c756de69a6475b72
MD5 83ac764064e841abff330320c57cd2ae
BLAKE2b-256 233917f2728c4243ee4a8797db0b4f3a8904a9690749b6b1fbe879cd42b93cc0

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 756.5 kB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 7dd15f935b78b840a87a80f394a4b313740bff6c5641c1ed7c37ff77361d3cc0
MD5 3823f66a5e67d0e1739f68e98ef89849
BLAKE2b-256 bd0a9b781008df5c45022b8f1eecc48c091f6e06dba7e4da434bc8bfdfb3b208

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 951.4 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 78706db3b72ae735b01ee7be9849a770b209c20a791e2107cacfe5254b65e32c
MD5 f5b4ce3ef5034b9b4d1cec803b46b40b
BLAKE2b-256 5e10b200560f183aa33b31b88c52b21fa7ba8d11d4ecf12eff995618913b9e9f

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 cb324a488c36e394cea6de427d20b51db59120bc767204aee5d157d92476f638
MD5 a37068b25f888181969496f0d65ccc66
BLAKE2b-256 330bb71b0acb7e4f5aace890bfaa7b2406d02b9d11d825b9ecb50f120e9fde38

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 687.5 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6783359a84cedfa9a7fd7f5e1faeffb742bb2d98c48c4cab973cbe9673fb207c
MD5 f975f40c07b8a277ca769a00bcfae631
BLAKE2b-256 80c060be736f7cf8655ef97723108e40d550a6f128cc220835a911fb522f7777

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 949.3 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ab3c5cf19a769b9a8f5e9dc9f4ff88bd0e9d0264590353b6679824d54663fff1
MD5 ebac00fec708b99af4dd1aa5a3335509
BLAKE2b-256 37b14bb9c410d7cb522bbe6a556e6438560f8ff61f17169f6728aa2a35442ca5

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 512fa1dedbc1056e108f5aa8a3b58bf20c018de2afa29b82444e0589de6e37db
MD5 bfd020bb8896074199dc01e32f32c174
BLAKE2b-256 8c419f77bbef9f9229fed9a0d91cb7dd2a887b891e345545300ab30c9a7c4273

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 688.9 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9ddc905582860bc588796793235c98f0643bb69c6f2470104feecc43054d956b
MD5 8fda0a3b9be9393a6dac5e5e87ea17bc
BLAKE2b-256 f581cf6559839f33f9a86959ca72457f293efc7549aa30e91b31dd5f8becfcb9

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 952.0 kB
  • Tags: CPython 3.6m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8a1959dcd2987bb667de153eca56deb1a9216dca3563234869306de034c6f35e
MD5 aabe29e68ca600a63535fdf53480f8c6
BLAKE2b-256 3ebc61ec0cbbf3650e95c99a30c5d56816a49d841141ee5234a67ea275097012

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 6f7d0f4936b9572bb28620a9a57f977336e46309c97d6f2cb0f51e23fb3d340a
MD5 d2bc6199f3b575f2df8a382b5d6f38a4
BLAKE2b-256 34cd91caaf4323d738ff3757271569ba4e9335c9b2bbc78500370d90a4ecbb7b

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 679.0 kB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 22ea0b8c7096ce335510f95f4957d445e21bc799a7552a4df019932b8d01cb69
MD5 52dc373ca9a78bd5de2a304ee4a7e474
BLAKE2b-256 fd41b1642ae2df00864b1ad6d1ef9d8fc5a1a73a50432dc6b25bcc1cf351a990

See more details on using hashes here.

File details

Details for the file lensfunpy-1.7.0-cp35-cp35m-macosx_10_9_intel.whl.

File metadata

  • Download URL: lensfunpy-1.7.0-cp35-cp35m-macosx_10_9_intel.whl
  • Upload date:
  • Size: 945.3 kB
  • Tags: CPython 3.5m, macOS 10.9+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.1

File hashes

Hashes for lensfunpy-1.7.0-cp35-cp35m-macosx_10_9_intel.whl
Algorithm Hash digest
SHA256 9f55fadd3a86c206368bce0a17df9c98ce6ca1e7d0259c4edd1bf3695319680d
MD5 c5eb5cfc7db19603f4a59e9a7da2b695
BLAKE2b-256 2aba1e8013654a2def861efa2cd93cc4cfdec3e209d78275d8dd167d423856b8

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