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
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.2.4-cp34-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19d737adbc436cd0bdae6049827ce21ca5dc51c0e9822b67be9aa0ceaa33da78 |
|
MD5 | 48ffcf11da46d529d781dd39e67f7638 |
|
BLAKE2b-256 | e84d0feccc67361623c985072b53c164aeffc25645d15d720656752cc4d647f3 |
Hashes for lensfunpy-1.2.4-cp34-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0825d7e8193ac74f035701095d65750c64922705f77e2df41302456fb8cdc7e |
|
MD5 | d451010c0da46d29cc54594a5a0b4bee |
|
BLAKE2b-256 | b7ec03500870ab320acd9fd75190636b3f9d15d4dba4e779cfcc251762d69b37 |
Hashes for lensfunpy-1.2.4-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 | 3fe10aa564dfa72d5c4decfb934e30ac1c95ca381097aec5c26c86a031db2369 |
|
MD5 | b3222dae2e3c677a385de25b00c5482e |
|
BLAKE2b-256 | 134f688d03276ba55e349b3cf212f7fb215a72f2d5581a1c6c4554dcc39cd46b |
Hashes for lensfunpy-1.2.4-cp33-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3738d2a94bf41b751aa16aa2c55391314e391db60a7d6ef7ad51be009178ff |
|
MD5 | cae175d15c86cd9df098d8725c9d63b0 |
|
BLAKE2b-256 | 5cc397d9508aca4d6d65a5d8ed01eb36235828df4c5153eeacca48fa0816597e |
Hashes for lensfunpy-1.2.4-cp33-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb097e75fa60cbfecfd1e18bfc4e49e15d8501acc5a370510aa92ae354db7c9b |
|
MD5 | 420478c15ef40dba02425bcd4f36128e |
|
BLAKE2b-256 | a2fdd0180c06833c79cf0b0888fc8e5ce4e587f36f74ecc3d0a9927e65f78540 |
Hashes for lensfunpy-1.2.4-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 | 5acf81466cb38a4d4a42bb2f1f96d7510db9f0fa368de108d194372919b1c4e6 |
|
MD5 | 24ef2de57df9258e786078340521a6f7 |
|
BLAKE2b-256 | 6e87e3fca11f188f0c4a9599c6ec5cb7bb75958d00f31b78f5ec9d5dd8259553 |
Hashes for lensfunpy-1.2.4-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6099124319aa48225d36d6720a6935d8694008daef9a62b94a48eb646ac814c9 |
|
MD5 | d40499d14ac62c9a6fa572292f2cacf5 |
|
BLAKE2b-256 | 46d9463173c0d7c95071f3a5a59a91ea384be8b8e45386414961e73b805523dc |
Hashes for lensfunpy-1.2.4-cp27-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f63737bbba10f127c6719a5dc6bc89b3aee787bd831fe44376e84354ff7f762 |
|
MD5 | ae911fc93fd699fc0d8464687087d8f9 |
|
BLAKE2b-256 | 26885a35a6bb2ede30fbeecaf8d8c3de5edd03bc01d8c2cd43bd2404de1a92d4 |
Hashes for lensfunpy-1.2.4-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 | 3b638a1a1fbf07cac5d3d3e712ab1c5e5a11541a7616dbff2310a3adebb69029 |
|
MD5 | cdd6a0a0570d64c6e73e117a919bf51f |
|
BLAKE2b-256 | 8d3fbf5a3f706584c5598705d0c997b7b9a62a11c5aabc611858871cf14356ea |