Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError in Python: "init() got an unexpected keyword argument 'fov'" when creating an instance of a Camera class

I’m working on a 3D rendering application in Python and encountered an issue when trying to create an instance of the Camera class. The error message I’m getting is:

TypeError: Camera.__init__() got an unexpected keyword argument 'fov'

Here’s the relevant code snippet:

class Scene():
    def __init__(self, ambient_color = vec3(0.01, 0.01, 0.01), n = vec3(1.0,1.0,1.0)) :
        # n = index of refraction (by default index of refraction of air n = 1.)
        self.scene_primitives = []
        self.collider_list = []
        self.shadowed_collider_list = []
        self.Light_list = []
        self.importance_sampled_list = []
        self.ambient_color = ambient_color
        self.n = n
        self.importance_sampled_list = []
    def add_Camera(self, look_from, look_at, **kwargs):
        self.camera = Camera(look_from, look_at, up_vector=vec3(0.0, 1.0, 0.0), fov=60.0, aspect_ratio=16.0 / 9.0, **kwargs)
class Camera():
    def __init__(self, look_from, look_at,up_vector,fov, aspect_ratio, screen_width = 400 ,screen_height = 300,  field_of_view = 90., aperture = 0., focal_distance = 1.):
        self.fov = fov
        self.aspect_ratio = aspect_ratio
        self.up_vector = up_vector
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.aspect_ratio = float(screen_width) / screen_height
        self.look_from = look_from
        self.look_at = look_at
        self.camera_width = np.tan(field_of_view * np.pi/180   /2.)*2.
        self.camera_height = self.camera_width/self.aspect_ratio
        self.cameraFwd = (look_at - look_from).normalize()
        self.cameraRight = (self.cameraFwd.cross(vec3(0.,1.,0.))).normalize()
        self.cameraUp = self.cameraRight.cross(self.cameraFwd)
        self.lens_radius =  aperture / 2.
        self.focal_distance = focal_distance
        self.x = np.linspace(-self.camera_width/2., self.camera_width/2., self.screen_width)
        self.y = np.linspace(self.camera_height/2., -self.camera_height/2., self.screen_height)
        xx,yy = np.meshgrid(self.x,self.y)
        self.x = xx.flatten()
        self.y = yy.flatten()
My_Scene.add_Camera(look_from = vec3(0*np.sin(angle), 0, 0*np.cos(angle)  -1.5 ),look_at = vec3(0, 0, 0),fov=60.0,aspect_ratio=16.0 / 9.0,up_vector=vec3(0.0, 1.0, 0.0),screen_width = 300 ,screen_height = 300)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I get a different error:

TypeError: main.Camera() got multiple values for keyword argument ‘fov’

The problem is that you have fov=60.0 in the arguments to Camera(), but it’s also in kwargs because you have it in the arguments to My_Scene.add_Camera().

Merge your default argument values with the ones that are passed in kwargs.

    def add_Camera(self, look_from, look_at, **kwargs):
        defaults = {'up_vector': vec3(0.0, 1.0, 0.0), 'fov': 60.0, 'aspect_ratio': 16.0/9.0}
        defaults.update(kwargs)
        self.camera = Camera(look_from, look_at, **defaults)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading