def get_calibration_mat(op, blender_camera):
    op.report({'INFO'}, 'get_calibration_mat: ...')
    scene = bpy.context.scene
    render_resolution_width = scene.render.resolution_x
    render_resolution_height = scene.render.resolution_y
    focal_length_in_mm = float(blender_camera.data.lens)
    sensor_width_in_mm = float(blender_camera.data.sensor_width)
    focal_length_in_pixel = \
        float(max(scene.render.resolution_x, scene.render.resolution_y)) * \
        focal_length_in_mm / sensor_width_in_mm

    max_extent = max(render_resolution_width, render_resolution_height)
    p_x = render_resolution_width / 2.0 - blender_camera.data.shift_x * max_extent
    p_y = render_resolution_height / 2.0 - blender_camera.data.shift_y * max_extent

    calibration_mat = Camera.compute_calibration_mat(focal_length_in_pixel,
                                                     cx=p_x,
                                                     cy=p_y)

    op.report({'INFO'},
              'render_resolution_width: ' + str(render_resolution_width))
    op.report({'INFO'},
              'render_resolution_height: ' + str(render_resolution_height))
    op.report({'INFO'}, 'focal_length_in_pixel: ' + str(focal_length_in_pixel))

    op.report({'INFO'}, 'get_calibration_mat: Done')
    return calibration_mat
Exemplo n.º 2
0
    def enhance_camera_with_intrinsics(self, cameras):

        intrinsic_missing = False
        for cam in cameras:
            if not cam.has_intrinsics():
                intrinsic_missing = True
                break

        if not intrinsic_missing:
            self.report({'INFO'}, 'Using intrinsics from file (.json).')
            return cameras, True
        else:
            self.report({'INFO'}, 'Using intrinsics from user options, since not present in the reconstruction file (.log).')
            if math.isnan(self.default_focal_length):
                self.report({'ERROR'}, 'User must provide the focal length using the import options.')
                return [], False 

            if math.isnan(self.default_pp_x) or math.isnan(self.default_pp_y):
                self.report({'WARNING'}, 'Setting the principal point to the image center.')

            for cam in cameras:
                if math.isnan(self.default_pp_x) or math.isnan(self.default_pp_y):
                    assert cam.width is not None    # If no images are provided, the user must provide a default principal point
                    assert cam.height is not None   # If no images are provided, the user must provide a default principal point
                    default_cx = cam.width / 2.0
                    default_cy = cam.height / 2.0
                else:
                    default_cx = self.default_pp_x
                    default_cy = self.default_pp_y
                
                intrinsics = Camera.compute_calibration_mat(
                    focal_length=self.default_focal_length, cx=default_cx, cy=default_cy)
                cam.set_calibration_mat(intrinsics)
            return cameras, True