Skip to main content

Python wrapper for the lensfun library

Project description

Build Status

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

Sample code

How to find cameras and lenses:

import lensfun

camMaker = 'NIKON CORPORATION'
camModel = 'NIKON D3S'
lensMaker = 'Nikon'
lensModel = 'Nikkor 28mm f/2.8D AF'

db = lensfun.Database()
cam = db.findCameras(camMaker, camModel)[0]
lens = db.findLenses(cam, lensMaker, lensModel)[0]

print cam
print lens

How to correct lens distortion:

import cv2 # OpenCV library

focalLength = 28.0
aperture = 1.4
distance = 10
imagePath = '/path/to/image.tiff'
undistortedImagePath = '/path/to/image_undist.tiff'

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

mod = lensfun.Modifier(lens, cam.CropFactor, width, height)
mod.initialize(focalLength, aperture, distance)

undistCoords = mod.applyGeometryDistortion()
imUndistorted = cv2.remap(im, undistCoords, None, cv.INTER_LANCZOS4)
cv2.imwrite(undistortedImagePath, imUndistorted)

Installation

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

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-0.9.1.tar.gz (61.0 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for lensfunpy-0.9.1.tar.gz
Algorithm Hash digest
SHA256 54d2efc1ebbe4c96cd8c01f4410b29ca2407bb062e165b5777646bbe06fa9b0e
MD5 99e1c0afd5d46300317c197ae9d50262
BLAKE2b-256 04f7017e7af383d95503aa374b1fd9f3b8d378d87d07b9982fe5253c12612b25

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