Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check type in lensfunpy.Modifier().initialize() #27

Open
dschneiderch opened this issue Oct 27, 2020 · 1 comment
Open

check type in lensfunpy.Modifier().initialize() #27

dschneiderch opened this issue Oct 27, 2020 · 1 comment

Comments

@dschneiderch
Copy link

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)
@letmaik
Copy link
Owner

letmaik commented Oct 27, 2020

Thanks for reporting, I can reproduce that.

The signature has the right type:

def __init__(self, Lens lens not None, float crop, int width, int height):

I would have thought Cython adds relevant checks to reject any objects that are not Lens...

EDIT: According to https://cython.readthedocs.io/en/latest/src/userguide/extension_types.html#extension-types-and-none it should check the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants