Skip to main content

Python wrapper for the lensfun library

Project description

Linux Build Status Mac Build Status Windows Build Status

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.

NumPy Dependency

Before installing lensfunpy, you need to have numpy installed. You can check your numpy version with pip freeze.

The minimum supported numpy version depends on your Python version:

Python

numpy

2.7 - 3.3

>= 1.7.1

3.4

>= 1.8.1

3.5

>= 1.9.3

You can install numpy with pip install numpy.

Installation on Windows and Mac OS X

Binaries are provided for Python 2.7, 3.3, 3.4, and 3.5 for both 32 and 64 bit. These can be installed with a simple pip install --use-wheel lensfunpy (or just pip install lensfunpy if using pip >= 1.5).

Installation on Linux

You need to have the lensfun library installed to use this wrapper.

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

sudo apt-get install liblensfun0 liblensfun-dev

Or install the latest developer version from the GIT repository:

git clone git://git.code.sf.net/p/lensfun/code lensfun
cd lensfun
cmake .
sudo make install

After that, it’s the usual pip install lensfunpy.

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 and apparently this folder is not searched for libraries by default in some Linux distributions.

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

lensfunpy-1.4.0.tar.gz (102.6 kB view details)

Uploaded Source

Built Distributions

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

lensfunpy-1.4.0-cp35-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.5Windows x86-64

lensfunpy-1.4.0-cp35-none-win32.whl (1.6 MB view details)

Uploaded CPython 3.5Windows x86

lensfunpy-1.4.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.5 MB view details)

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

lensfunpy-1.4.0-cp34-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.4Windows x86-64

lensfunpy-1.4.0-cp34-none-win32.whl (1.6 MB view details)

Uploaded CPython 3.4Windows x86

lensfunpy-1.4.0-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.4mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

lensfunpy-1.4.0-cp33-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.3Windows x86-64

lensfunpy-1.4.0-cp33-none-win32.whl (1.6 MB view details)

Uploaded CPython 3.3Windows x86

lensfunpy-1.4.0-cp33-cp33m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.3mmacOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

lensfunpy-1.4.0-cp27-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 2.7Windows x86-64

lensfunpy-1.4.0-cp27-none-win32.whl (1.6 MB view details)

Uploaded CPython 2.7Windows x86

lensfunpy-1.4.0-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.5 MB view details)

Uploaded CPython 2.7macOS 10.10+ Intel (x86-64, i386)macOS 10.10+ x86-64macOS 10.6+ Intel (x86-64, i386)macOS 10.9+ Intel (x86-64, i386)macOS 10.9+ x86-64

File details

Details for the file lensfunpy-1.4.0.tar.gz.

File metadata

  • Download URL: lensfunpy-1.4.0.tar.gz
  • Upload date:
  • Size: 102.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lensfunpy-1.4.0.tar.gz
Algorithm Hash digest
SHA256 5570e1c09835abce2f84c7b8fe34c1d0bd4751b472610dba123459e6dc9e5bcd
MD5 4231d84f3c78ef669010d1ac823780e0
BLAKE2b-256 f2070f0049952359a45df3a9ad611824ce81c803d26ef22aff3c2c71f4b4c07e

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp35-none-win_amd64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 9799086bc7cc0c42511f6f84a0f33b5ee84334041a8f4588b549ccd37e4e6c37
MD5 388f1eb2bf4b86e54ce5ef5c02e63727
BLAKE2b-256 bba222e774b715e14bd16d83b0575d1c10fece71df6f5fe71e6d678378c4e96b

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp35-none-win32.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp35-none-win32.whl
Algorithm Hash digest
SHA256 062b3a63461c721299783d1303bdf9eb8a91a53f7c7fa1dbcf804e71eaebdf60
MD5 388d310a56964e6a2350b18b8d46e9b8
BLAKE2b-256 869b51d811c5179e1b639b5896c9818f80a438b7078446f8d1c56545e88ae5ea

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 1c48ae0dc1270daae21a5194a01910e712f1bd036a2657f77b22b65bc455a197
MD5 ddf7fbd7e9492718fc628d50a18457f5
BLAKE2b-256 2058b456fbea64f944858cb7bd08f04b4427ac884cad9216c7139a01c1c07c95

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp34-none-win_amd64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp34-none-win_amd64.whl
Algorithm Hash digest
SHA256 001f3154834e90f11b92ad5f8d50fbec70e388cc6e4c114c63bb8dea6bf86629
MD5 729b9622fea8efb712084bde0ba03f69
BLAKE2b-256 799175dd3189c370042f024add5675f2ca8f9009fc550959b8a1c7b8033cc863

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp34-none-win32.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp34-none-win32.whl
Algorithm Hash digest
SHA256 9ef5d12836000d169c16ad8c2eab216f8ad09b8470fe52d6b1f36d56945e7e6d
MD5 fc958fea37b616be1e3e2ea696cb6a20
BLAKE2b-256 39c5712c3148e0ed7bdc620e67dad09d9d68a8fc6ddbb550078341be183beb1d

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 ece5c9d715cdfa01f311c138cdd823a0d03cd1610d548593154b5a258f9ecdd3
MD5 bb846b9155d69dca88e4f44cded6a9a3
BLAKE2b-256 0e4cefcc2ef935be705ab16f220adb6f952f7f1372b5feb51529d79c69fdab5d

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp33-none-win_amd64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp33-none-win_amd64.whl
Algorithm Hash digest
SHA256 94c7e5c886851ab4df495c6de0ab56f077572b3d3650377f02c812521a465814
MD5 9d842b1e780786b4bdb848ee99307179
BLAKE2b-256 1be810fc35e2c2b26921f9eeb06dbe5cfeb0acbc6666d3e8ab672e5d999fe033

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp33-none-win32.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp33-none-win32.whl
Algorithm Hash digest
SHA256 58d8178c1dabac2d17da93a4834b7b14dadf4dba4dbdbd000b1ce5be103cf5d9
MD5 27c0d0fc4184a2e86c0b483184ee8796
BLAKE2b-256 f81cf4371fe6486e77a06eb7a92d696f2d473852a2a76d651b6c2439547278b4

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp33-cp33m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp33-cp33m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 9aab8e8ee6b4d64fa854f65dba153a623367a9c79d383228b44e6cb8c57ed979
MD5 7d5f71f0a5ecd2666de84667fb661170
BLAKE2b-256 5fab2737edbdcd4da43ae8a087aa6322fbaf5b65a3439b0e7f3676db08707648

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp27-none-win_amd64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp27-none-win_amd64.whl
Algorithm Hash digest
SHA256 be5b8e8b0168ab10de723c0bc36bc06c5db29a339a249123d9473cc39df59c0b
MD5 476e37654e4734fe5474625fa46fbaf8
BLAKE2b-256 df321d41a72436d4a4dd8a2c50bd09dffc6d580f859e249a3b84111ef172246a

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp27-none-win32.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp27-none-win32.whl
Algorithm Hash digest
SHA256 378bc6b0dcad5b4b6bf54e90f2008d89dea50ff265d3800b1f344cffdd5a2d0f
MD5 c468b20af5aba565416e8bdcb06eacb3
BLAKE2b-256 72751001c294e78826e88386e95fe9c87484443e842f0f5c325a44c61157adc9

See more details on using hashes here.

File details

Details for the file lensfunpy-1.4.0-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for lensfunpy-1.4.0-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 4843928fdcbe0636fdf730cc5bd21f48b8aa31a785de663ec7397d82b188d9ad
MD5 931c4e37b1038597d56ae91d0ec1db0a
BLAKE2b-256 f8b2318c7035a831650140a731af6c873e6791f9ab5b2e868b35d554bb02c39c

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