- 
                Notifications
    You must be signed in to change notification settings 
- Fork 21
Open
Labels
Description
a small usability improvement suggestion. I was consistently getting a segfault error at initialize with the code below because I forgot to include the [0] indexing for lens.  It would make sense to check that lens is of type lensfunpy._lensfun.Lens and cam is of type lensfunpy._lensfun.Camera
import lensfunpy
import cv2
import piexif
image_path = 'swirf16.tif'
img_png = image_path+'.png'
undistorted_image_path = image_path+'-corrected.png'
im = cv2.imread(image_path)
cv2.imwrite(img_png, im)
height, width = im.shape[0], im.shape[1]
meta = piexif.load(image_path)
focal_length=meta['Exif'][37386]
focal_length = focal_length[0]/focal_length[1]
aperture = meta['Exif'][33437]
aperture = aperture[0]/aperture[1]
distance = .3
cam_make = meta['0th'][271]
cam_model = meta['0th'][272]
lens_make = meta['Exif'][42035]
lens_model=meta['Exif'][42036]
db = lensfunpy.Database()
cam = db.find_cameras(cam_make, cam_model)[0]
lens = db.find_lenses(cam, lens_make, lens_model)
mod = lensfunpy.Modifier(lens, cam.crop_factor, width, height)
mod.initialize(focal_length, aperture, distance)