cameratools.py¶
NOTE: This module is a feature under developement.
- class CameraTools[source]¶
Bases:
object
- static calc_resolution_from_sim_2d(pixels_count, coords, pixels_border, view_plane_axes=(0, 1))[source]¶
- static pos_fill_frame(coords_world, pixel_num, pixel_size, focal_leng, cam_rot, frame_fill=1.0)[source]¶
- static pos_fill_frame_all(coords_world_list, pixel_num, pixel_size, focal_leng, cam_rot, frame_fill=1.0)[source]¶
- static calculate_FOV(cam_data)[source]¶
A method to calulate the camera’s field of view in mm
- Parameters:
cam_data (
CameraData
) – A dataclass containing the camera parameters- Returns:
tuple[float
,float]
– A tuple containing the field of view in mm in both x and y directions
- static blender_FOV(cam_data)[source]¶
A method to calculate the camera’s field of view in mm using Blender’s method. This method differs due to one simplification.
- Parameters:
cam_data (
CameraData
) – A dataclass containing the camera parameters- Returns:
tuple[float
,float]
– A tuple containing the FOV in x and y directions
- static calculate_mm_px_resolution(cam_data)[source]¶
Function to calculate the mm/px resolution of a camera
- Parameters:
cam_data (
CameraData
) – A dataclass containing the camera parameters- Returns:
float
– The mm/px resolution
- static focal_length_from_resolution(pixels_size, working_dist, resolution)[source]¶
A method to calculate the required focal length to achieve a certain resolution. This is calculated given the pixel size and working distance. This method can be used for a 2D setup or for camera 0 for a stereo setup.
- Parameters:
pixels_size (
np.ndarray
) – The camera pixel size in the x and y directions (in mm).working_dist (
float
) – The working distance of the camera to the sample.resolution (
float
) – The desired resolution in mm/px.
- Returns:
float
– The focal length required to obtain the desired image resolution.
- static blender_camera_from_resolution(pixels_num, pixels_size, working_dist, resolution)[source]¶
A convenience function to create a camera object in Blender from its pixels, the pixel size, the working distance and desired resolution.
- Parameters:
pixels_num (
np.ndarray
) – The number of pixels in the camera, in the x and y directions.pixels_size (
np.ndarray
) – The camera pixels size in mm, in the x and y directions.working_dist (
float
) – The working distance of the camera.resolution (
float
) – The desired mm/px resolution
- Returns:
CameraData
– A dataclass containing the created camera’s parameters.
- static symmetric_stereo_cameras(cam_data_0, stereo_angle)[source]¶
A convenience function to set up a symmetric stereo camera system, given an initial CameraData dataclass and a stereo angle. This assumes the basic camera parameters are the same.
- Parameters:
cam_data_0 (
CameraData
) – A dataclass containing the camera parameters for a single camera, which will be camera 0.stereo_angle (
float
) – The stereo angle between the two cameras.
- Returns:
CameraStereo
– An instance of the CameraStereo class. This class contains information about each of the cameras, as well as the extrinsic parameters between them.
- static faceon_stereo_cameras(cam_data_0, stereo_angle)[source]¶
A convenience function to set up a face-on stereo camera system, given an initial CameraData dataclass and a stereo angle. This assumes the basic camera parameters are the same.
- Parameters:
cam_data_0 (
CameraData
) – A dataclass containing the camera parameters for a single camera, which will be camera 0.stereo_angle (
float
) – The stereo angle between the two cameras.
- Returns:
CameraStereo
– An instance of the CameraStereo class. This class contains information about each of the cameras, as well as the extrinsic parameters between them.