def get_calibration_mat(blender_camera, op=None):
    """Derive calibration matrix from a Blender camera object."""
    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
    )
    return calibration_mat
Derive calibration matrix from a Blender camera object.
photogrammetry_importer/importers/camera_utility.py