pyrobot.algorithms.camera_transform.
CameraTransform
(configs, world, ros_launch_manager=None, robots={}, sensors={}, algorithms={})[source]¶Bases: pyrobot.algorithms.algorithm.Algorithm
Base class of Camera Transform algorithms.
Specifically, this algorithm handles getting transformation from image to 3D points. It also give access to camera intrinsics and extrinsics.
__init__
(configs, world, ros_launch_manager=None, robots={}, sensors={}, algorithms={})[source]¶Initialize self. See help(type(self)) for accurate signature.
check_cfg
()[source]¶This function checks required configs shared by all camera transform instances in constructor.
The camera transform algorithm handles one camera, and one camera only
The camera is either a component of a robot or a sensor
The camera has a base frame and an camera frame
The camera has intrinsic params: fx, fy, cx, cy
The camera has image size specified
with customized algorithm config checks after calling this function using super().check_cfg()
get_intrinsics
()[source]¶intrinsics_matrix: a 3x3 matrix structured as: K = [
[fx, 0, cx], [0, fy, cy], [0, 0, 1 ],
] where f is focal length and c is center pixel.
get_transform_matrix
(source_frame, target_frame)[source]¶get a transform from source frame to target frame.
source_frame: string of source frame name target_frame: string of target frame name
transformation_matrix: a 4x4 matrix structured as: M = [
[Rxx, Rxy, Rxz, tx], [Ryx, Ryy, Ryz, ty], [Rzx, Rzy, Rzz, tz], [0, 0, 0, 1 ]
] such that for any point p = [x, y, z] in source frame, construct p’ = [x, y, z, 1], Mp’ gives you rotated and translated point in target frame; construct p’’ = [x, y, z, 0], Mp’’ gives you rotated point (no translation) in target frame.
pcd_from_img
(depth_img, rgb_img=None, in_cam=True)[source]¶and map to 3d point in camera frame or in specified base frame.
depth_img: array of depth image with shape (Camera.height, Camera.width) rgb_img: array of rgb image with shape (Camera.height, Camera.width, 3). Default: None.
If None, the function would only return 3D points but not color.
If True, the function would return 3D point cloud w.r.t camera frame; else it would return points w.r.t base frame specified in camera configs.
where n is the number of valid points in depth image. Each of the n entries is an [x, y, z] vector
where n is the number of valid points in depth image. Each of the n entries is an [r, g, b] vector If rgb_img is None, colors would be None.
pix_to_pt
(rows, columns, depth_img, rgb_img=None, in_cam=True)[source]¶and map to 3d point in camera frame or in specified base frame.
rows: list-like vector of indices of the rows of queried pixels, length is number of queried pixels. columns: list-like vector of indices of the columns of queried pixels, length should be the same as rows. depth_img: array of depth image with shape (Camera.height, Camera.width) rgb_img: array of rgb image with shape (Camera.height, Camera.width, 3). Default: None.
If None, the function would only return 3D points but not color.
If True, the function would return 3D points w.r.t camera frame; else it would return points w.r.t base frame specified in camera configs.
Each of the n entries is an [x, y, z] vector
Each of the n entries is an [r, g, b] vector If rgb_img is None, colors would be None.