Python wrapper for the lensfun library
Project description
lensfunpy is an easy-to-use Python wrapper for the lensfun library.
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)
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.
Installation on Windows and Mac OS X
Binaries are provided for Python 2.7, 3.3 and 3.4 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).
Binaries for other Python versions are currently not produced but if there is a need then this is possible as well. In that case, just contact me.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for lensfunpy-1.3.0-cp34-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ff277bb013fe5cb64a3d2fe1b64235a852418096346c8901c3aa9520d36c104 |
|
MD5 | 0f5766b4875d5a5cf0a2e846a82222aa |
|
BLAKE2b-256 | bfbdba2d18d5c263a8ff89bac1c752f0d68f8e2d9d741871ca4bf07eeced3cff |
Hashes for lensfunpy-1.3.0-cp34-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c22fd0bd53d4cf0f57c302653d80307e5966086f912a95855d338b21a588c5 |
|
MD5 | dad2c808ef639f6d8a5b16d69c5ccedf |
|
BLAKE2b-256 | 3a62758f45cc95c78e18c3ec7d966d543264b9d08d47676aeaaab7128d64b758 |
Hashes for lensfunpy-1.3.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 | aa7f62dc5ce71f632b9933634474ad60d9ade37d6f6de1dd329b9459edfa54df |
|
MD5 | b4915fc7b487eb7fe91185c08e160fde |
|
BLAKE2b-256 | d75a86be4dfe5bb5414a3299682461023bf0ab75592a1a6b61141c34c9418622 |
Hashes for lensfunpy-1.3.0-cp33-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be904159d13235f2bc9f054b9d635fdd65d74d2847104eb9eef1c390f25c10ea |
|
MD5 | 3e7ce804b224ec54f2985f9f8bd24f54 |
|
BLAKE2b-256 | 7c569bfc26f1e92b5a847e79a9ecbce0556cfe996a116edb865c3cc615c9b9a3 |
Hashes for lensfunpy-1.3.0-cp33-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a49bca1dba84061d81b302ff310cf60b941ceaeb02e677b966248af3ab577e37 |
|
MD5 | d8e42bb92fc5553a2d05a7cd76a90b51 |
|
BLAKE2b-256 | 1a0735575a590a1fdd50d6cdfaeb55106b10a739042ee46b8b4bc4fc2e6e09bb |
Hashes for lensfunpy-1.3.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 | 7be7b00b2e6e1878392214d6d913357941630b5d6f992a96641e8272271765ac |
|
MD5 | bfc45fa6e41dc1f43f3fbb6f51e0d236 |
|
BLAKE2b-256 | 38c64326e5468324c33691a52dbdedeb3a45b7cf47f415340e9c8b7089af94e5 |
Hashes for lensfunpy-1.3.0-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d14b355c7b9fb813bef9988d9181cae3f34624e83219f6ba37c2fb1a7ff1520 |
|
MD5 | d8a32052fb76e458c1d5b95ecb197ba1 |
|
BLAKE2b-256 | 1ff025760ecb1984f7f573f6e4732748d37930d467b31de7b2dcb12a90c9cd09 |
Hashes for lensfunpy-1.3.0-cp27-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a1a8ee2fe0e8e1d24fadde4882df5f93019ec2317536c5485ec8d678d815985 |
|
MD5 | d5fc2ebaab0865122fe284c31231e159 |
|
BLAKE2b-256 | ef191e0720dc9f129eefce601cde559cd8be8591e254b92a4f118f7fb76f61ec |
Hashes for lensfunpy-1.3.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 | fa1e01d3c956b008608a3cefc988e640ca70d4d2d54d9ab0a719d3ef8282c5f1 |
|
MD5 | 9ae225e44aa942474efd3a429de1d82b |
|
BLAKE2b-256 | 716497502dd26cadb3a00e5b56a906e4e66bf4052e6fd3638350cf7ff4916780 |