blenderproc.python.camera.CameraUtility module
Camera utility, collection of useful camera functions.
- blenderproc.python.camera.CameraUtility.add_camera_pose(cam2world_matrix, frame=None)[source]
Sets a new camera pose to a new or existing frame
- Parameters:
cam2world_matrix (
Union
[ndarray
,Matrix
]) – The transformation matrix from camera to world coordinate systemframe (
Optional
[int
]) – Optional, the frame to set the camera pose to.
- Return type:
int
- Returns:
The frame to which the pose has been set.
- blenderproc.python.camera.CameraUtility.add_depth_of_field(focal_point_obj, fstop_value, aperture_blades=0, aperture_rotation=0.0, aperture_ratio=1.0, focal_distance=-1.0)[source]
Adds depth of field to the given camera, the focal point will be set by the focal_point_obj, ideally an empty instance is used for this see bproc.object.create_empty() on how to init one of those. A higher fstop value makes the resulting image look sharper, while a low value decreases the sharpness.
Check the documentation on https://docs.blender.org/manual/en/latest/render/cameras.html#depth-of-field
- Parameters:
focal_point_obj (
Entity
) – The used focal point, if the object moves the focal point will move with itfstop_value (
float
) – A higher fstop value, will increase the sharpness of the sceneaperture_blades (
int
) – Amount of blades used in the cameraaperture_rotation (
float
) – Rotation of the blades in the camera in radiantaperture_ratio (
float
) – Ratio of the anamorphic bokeh effect, below 1.0 will give a horizontal one, above one a vertical one.focal_distance (
float
) – Sets the distance to the focal point when no focal_point_obj is given.
- blenderproc.python.camera.CameraUtility.get_camera_frustum(clip_start=None, clip_end=None, frame=None)[source]
Get the current camera frustum as eight 3D coordinates.
- Parameters:
clip_start (
Optional
[float
]) – The distance between the camera pose and the near clipping plane.clip_end (
Optional
[float
]) – The distance between the camera pose and the far clipping plane.frame (
Optional
[int
]) – The frame number whose assigned camera pose should be used. If None is give, the current frame is used.
- Return type:
ndarray
- Returns:
The eight 3D coordinates of the camera frustum
- blenderproc.python.camera.CameraUtility.get_camera_frustum_as_object(clip_start=None, clip_end=None, frame=None)[source]
Get the current camera frustum as deformed cube
- Parameters:
clip_start (
Optional
[float
]) – The distance between the camera pose and the near clipping plane.clip_end (
Optional
[float
]) – The distance between the camera pose and the far clipping plane.frame (
Optional
[int
]) – The frame number whose assigned camera pose should be used. If None is give, the current frame is used.
- Return type:
- Returns:
The newly created MeshObject
- blenderproc.python.camera.CameraUtility.get_camera_pose(frame=None)[source]
Returns the camera pose in the form of a 4x4 cam2world transformation matrx.
- Parameters:
frame (
Optional
[int
]) – The frame number whose assigned camera pose should be returned. If None is give, the current frame is used.- Return type:
ndarray
- Returns:
The 4x4 cam2world transformation matrix.
- blenderproc.python.camera.CameraUtility.get_fov()[source]
Returns the horizontal and vertical FOV of the current camera.
Blender also offers the current FOV as direct attributes of the camera object, however at least the vertical FOV heavily differs from how it would usually be defined.
- Return type:
Tuple
[float
,float
]- Returns:
The horizontal and vertical FOV in radians.
- blenderproc.python.camera.CameraUtility.get_intrinsics_as_K_matrix()[source]
Returns the current set intrinsics in the form of a K matrix.
This is basically the inverse of the the set_intrinsics_from_K_matrix() function.
- Return type:
ndarray
- Returns:
The 3x3 K matrix
- blenderproc.python.camera.CameraUtility.get_projection_matrix(clip_start=None, clip_end=None)[source]
Returns the projection matrix, it allows to overwrite the current used values for the near and far clipping plane.
- Parameters:
clip_start (
Optional
[float
]) – The distance between the camera pose and the near clipping plane.clip_end (
Optional
[float
]) – The distance between the camera pose and the far clipping plane.
- Return type:
ndarray
- Returns:
The 4x4 projection matrix of the current camera
- blenderproc.python.camera.CameraUtility.get_sensor_size(cam)[source]
Returns the sensor size in millimeters based on the configured sensor_fit.
- Parameters:
cam (
Camera
) – The camera object.- Return type:
float
- Returns:
The sensor size in millimeters.
- blenderproc.python.camera.CameraUtility.get_view_fac_in_px(cam, pixel_aspect_x, pixel_aspect_y, resolution_x_in_px, resolution_y_in_px)[source]
Returns the camera view in pixels.
- Parameters:
cam (
Camera
) – The camera object.pixel_aspect_x (
float
) – The pixel aspect ratio along x.pixel_aspect_y (
float
) – The pixel aspect ratio along y.resolution_x_in_px (
int
) – The image width in pixels.resolution_y_in_px (
int
) – The image height in pixels.
- Return type:
int
- Returns:
The camera view in pixels.
- blenderproc.python.camera.CameraUtility.is_point_inside_camera_frustum(point, clip_start=None, clip_end=None, frame=None)[source]
Checks if a given 3D point lies inside the camera frustum.
- Parameters:
point (
Union
[List
[float
],Vector
,ndarray
]) – The point, which should be checkedclip_start (
Optional
[float
]) – The distance between the camera pose and the near clipping plane.clip_end (
Optional
[float
]) – The distance between the camera pose and the far clipping plane.frame (
Optional
[int
]) – The frame number whose assigned camera pose should be used. If None is give, the current frame is used.
- Return type:
bool
- Returns:
True, if the point lies inside the camera frustum, else False
- blenderproc.python.camera.CameraUtility.rotation_from_forward_vec(forward_vec, up_axis='Y', inplane_rot=None)[source]
Returns a camera rotation matrix for the given forward vector and up axis
- Parameters:
forward_vec (
Union
[ndarray
,Vector
]) – The forward vector which specifies the direction the camera should look.up_axis (
str
) – The up axis, usually Y.inplane_rot (
Optional
[float
]) – The inplane rotation in radians. If None is given, the inplane rotation is determined only based on the up vector.
- Return type:
ndarray
- Returns:
The corresponding rotation matrix.
- blenderproc.python.camera.CameraUtility.set_intrinsics_from_K_matrix(K, image_width, image_height, clip_start=None, clip_end=None)[source]
Set the camera intrinsics via a K matrix.
- The K matrix should have the format:
- [[fx, 0, cx],
[0, fy, cy], [0, 0, 1]]
This method is based on https://blender.stackexchange.com/a/120063.
- Parameters:
K (
Union
[ndarray
,Matrix
]) – The 3x3 K matrix.image_width (
int
) – The image width in pixels.image_height (
int
) – The image height in pixels.clip_start (
Optional
[float
]) – Clipping start.clip_end (
Optional
[float
]) – Clipping end.
- blenderproc.python.camera.CameraUtility.set_intrinsics_from_blender_params(lens=None, image_width=None, image_height=None, clip_start=None, clip_end=None, pixel_aspect_x=None, pixel_aspect_y=None, shift_x=None, shift_y=None, lens_unit=None)[source]
Sets the camera intrinsics using blenders represenation.
- Parameters:
lens (
Optional
[float
]) – Either the focal length in millimeters or the FOV in radians, depending on the given lens_unit.image_width (
Optional
[int
]) – The image width in pixels.image_height (
Optional
[int
]) – The image height in pixels.clip_start (
Optional
[float
]) – Clipping start.clip_end (
Optional
[float
]) – Clipping end.pixel_aspect_x (
Optional
[float
]) – The pixel aspect ratio along x.pixel_aspect_y (
Optional
[float
]) – The pixel aspect ratio along y.shift_x (
Optional
[int
]) – The shift in x direction.shift_y (
Optional
[int
]) – The shift in y direction.lens_unit (
Optional
[str
]) – Either FOV or MILLIMETERS depending on whether the lens is defined as focal length in millimeters or as FOV in radians.
- blenderproc.python.camera.CameraUtility.set_resolution(image_width=None, image_height=None)[source]
Sets the camera resolution.
- Parameters:
image_width (
Optional
[int
]) – The image width in pixels.image_height (
Optional
[int
]) – The image height in pixels.
- blenderproc.python.camera.CameraUtility.set_stereo_parameters(convergence_mode, convergence_distance, interocular_distance)[source]
Sets the stereo parameters of the camera.
- Parameters:
convergence_mode (
str
) – How the two cameras converge (e.g. Off-Axis where both cameras are shifted inwards to converge in the convergence plane, or parallel where they do not converge and are parallel). Available: [“OFFAXIS”, “PARALLEL”, “TOE”]convergence_distance (
float
) – The convergence point for the stereo cameras (i.e. distance from the projector to the projection screen)interocular_distance (
float
) – Distance between the camera pair