pyrcareworld.utils package#
Submodules#
pyrcareworld.utils.active_depth_generate module#
- pyrcareworld.utils.active_depth_generate.calc_depth_and_pointcloud(disparity: ndarray, mask: ndarray, q: ndarray, no_pointcloud: bool = False) Tuple[ndarray, object][source]#
Calculate depth and pointcloud.
- Parameters:
disparity β Disparity
mask β Valid mask
q β Perspective transformation matrix
no_pointcloud
- Return depth:
Depth
- Return pointcloud:
Pointcloud
- pyrcareworld.utils.active_depth_generate.calc_disparity(imgl: ndarray, imgr: ndarray, method: str, *, ndisp: int = 96, min_disp: int = 0, lr_consistency: bool = True, use_census: bool = True, census_wsize: int = 7) ndarray[source]#
Calculate disparity given a rectified image pair.
- Parameters:
imgl β Left image
imgr β Right image
method β SGBM or BM
ndisp β max disparity
min_disp β min disparity
lr_consistency β Use Left-Right Consistency (LRC) check
- Returns:
disparity
- pyrcareworld.utils.active_depth_generate.calc_main_depth_from_left_right_ir(ir_l: ndarray, ir_r: ndarray, rt_l: ndarray, rt_r: ndarray, rt_main: ndarray, k_l: ndarray, k_r: ndarray, k_main: ndarray, method: str = 'SGBM', ndisp: int = 96, use_noise: bool = True, use_census: bool = True, lr_consistency: bool = False, register_depth: bool = True, register_blur_ksize: int = 5, main_cam_size=(1920, 1080), census_wsize=7, **kwargs) ndarray[source]#
Calculate depth for rgb camera from left right ir images.
- Parameters:
ir_l β left ir image
ir_r β right ir image
rt_l β left extrinsic matrix
rt_r β right extrinsic matrix
rt_main β rgb extrinsic matrix
k_l β left intrinsic matrix
k_r β right intrinsic matrix
k_main β rgb intrinsic matrix
method β method for depth calculation (SGBM or BM)
use_noise β whether to simulate ir noise before processing
lr_consistency β whether to use left-right consistency check
- Return depth:
calculated depth
- pyrcareworld.utils.active_depth_generate.calc_rectified_stereo_pair(imgl: ndarray, imgr: ndarray, kl: ndarray, kr: ndarray, rt: ndarray, distortl: ndarray | None = None, distortr: ndarray | None = None) Tuple[ndarray, ndarray, ndarray][source]#
Rectify an image pair with given camera parameters.
- Parameters:
imgl β Left image
imgr β Right image
kl β Left intrinsic matrix
kr β Right intrinsic matrix
rt β Extrinsic matrix (left to right)
distortr β Left distortion coefficients
distortl β Right distortion coefficients
- Return imgl_rect:
Rectified left image
- Return imgr_rect:
Rectified right image
- Return q:
Perspective transformation matrix (for cv2.reprojectImageTo3D)
- pyrcareworld.utils.active_depth_generate.depth_post_processing(depth: ndarray, ksize: int = 5) ndarray[source]#
- pyrcareworld.utils.active_depth_generate.sim_ir_noise(img: ndarray, scale: float = 0.0, blur_ksize: int = 0, blur_ksigma: float = 0.03, speckle_shape: float = 398.12, speckle_scale: float = 0.00254, gaussian_mu: float = -0.231, gaussian_sigma: float = 0.83, seed: int = 0) ndarray[source]#
TODO: IR density model
Simulate IR camera noise.
Noise model from Landau et al. Simulating Kinect Infrared and Depth Images
- Parameters:
img β Input IR image
scale β Scale for downsampling & applying gaussian blur
blur_ksize β Kernel size for gaussian blur
blur_ksigma β Kernel sigma for gaussian blur
speckle_shape β Shape parameter for speckle noise (Gamma distribution)
speckle_scale β Scale parameter for speckle noise (Gamma distribution)
gaussian_mu β mu for additive gaussian noise
gaussian_sigma β sigma for additive gaussian noise
seed β random seed used for numpy
- Returns:
Processed IR image
pyrcareworld.utils.coordinate_system_converter module#
- class pyrcareworld.utils.coordinate_system_converter.CoordinateSystemConverter(cs1_direction=['right', 'up', 'forward'], cs2_direction=['right', 'up', 'forward'])[source]#
Bases:
objectCoordinate System Converter class.
- Parameters:
cs1_direction β list, The visual direction corresponding to the xyz axis, can be: [βleftβ/βrightβ/βupβ/βdownβ/βforwardβ/βbackβ/ βlβ/βrβ/βuβ/βdβ/βfβ/βbβ/ β-leftβ/β-rightβ/β-upβ/β-downβ/β-forwardβ/β-backβ/ β-lβ/β-rβ/β-uβ/β-dβ/β-fβ/β-bβ]
cs2_direction β list, The visual direction corresponding to the xyz axis, can be: [βleftβ/βrightβ/βupβ/βdownβ/βforwardβ/βbackβ/ βlβ/βrβ/βuβ/βdβ/βfβ/βbβ/ β-leftβ/β-rightβ/β-upβ/β-downβ/β-forwardβ/β-backβ/ β-lβ/β-rβ/β-uβ/β-dβ/β-fβ/β-bβ]
- cs1_matrix_to_cs2_matrix(matrix) ndarray[source]#
Convert rotation matrix from Coordinate System 1 to Coordinate System 2.
- Parameters:
matrix β List or np.ndarray shape [3, 3], rotation matrix of Coordinate System 1.
- Returns:
np.ndarray shape [3, 3], rotation matrix of Coordinate System 2.
- cs1_pos_to_cs2_pos(pos: list) list[source]#
Convert position from Coordinate System 1 to Coordinate System 2.
- Parameters:
pos β List of length 3, position of Coordinate System 1.
- Returns:
List of length 3, position of Coordinate System 2.
- cs1_quat_to_cs2_quat(quat: list) list[source]#
Convert quaternion from Coordinate System 1 to Coordinate System 2.
- Parameters:
quat β List of length 4, quaternion of Coordinate System 1.
- Returns:
List of length 4, quaternion of Coordinate System 2.
- cs1_scale_to_cs2_scale(scale: list) list[source]#
Convert scale from Coordinate System 1 to Coordinate System 2.
- Parameters:
scale β List of length 3, scale of Coordinate System 1.
- Returns:
List of length 3, scale of Coordinate System 2.
- cs2_matrix_to_cs1_matrix(matrix) ndarray[source]#
Convert rotation matrix from Coordinate System 2 to Coordinate System 1.
- Parameters:
matrix β List or np.ndarray shape [3, 3], rotation matrix of Coordinate System 2.
- Returns:
np.ndarray shape [3, 3], rotation matrix of Coordinate System 1.
- cs2_pos_to_cs1_pos(pos: list) list[source]#
Convert position from Coordinate System 2 to Coordinate System 1.
- Parameters:
pos β List of length 3, position of Coordinate System 2.
- Returns:
List of length 3, position of Coordinate System 1.
- cs2_quat_to_cs1_quat(quat: list) list[source]#
Convert quaternion from Coordinate System 2 to Coordinate System 1.
- Parameters:
quat β List of length 4, quaternion [x, y, z, w] of Coordinate System 2.
- Returns:
List of length 4, quaternion [x, y, z, w] of Coordinate System 1.
- cs2_scale_to_cs1_scale(scale: list) list[source]#
Convert scale from Coordinate System 2 to Coordinate System 1.
- Parameters:
scale β List of length 3, scale of Coordinate System 2.
- Returns:
List of length 3, scale of Coordinate System 1.
pyrcareworld.utils.depth_processor module#
pyrcareworld.utils.interpolate_utils module#
pyrcareworld.utils.locker module#
pyrcareworld.utils.os_utils module#
pyrcareworld.utils.proc_wrapper module#
pyrcareworld.utils.rfuniverse_communicator module#
- class pyrcareworld.utils.rfuniverse_communicator.RFUniverseCommunicator(port: int = 5004, receive_data_callback=None, proc_type='editor')[source]#
Bases:
Thread- run()[source]#
Method representing the threadβs activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the objectβs constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
pyrcareworld.utils.rfuniverse_utility module#
- pyrcareworld.utils.rfuniverse_utility.EncodeIDAsColor(instance_id: int)[source]#
Encode the object id to a color.
- Parameters:
instance_id β Int, the id of the object.
- Returns:
The encoded color in [r, g, b, 255] format.
- Return type:
List
- pyrcareworld.utils.rfuniverse_utility.GetMatrix(quat=[0, 0, 0, 1]) ndarray[source]#
Transform the position and quaternion into a transformation matrix.
- Parameters:
quat β List of length 4, representing the [x, y, z, w] quaternion.
- Returns:
the transformation matrix.
- Return type:
numpy.ndarray
- pyrcareworld.utils.rfuniverse_utility.UnityEulerToQuaternion(eular: list) list[source]#
Transform euler angle to quaternion in Unity.
- Parameters:
eular β List of length 3, representing euler angle in [x, y, z]
degree. (order and measured in)
- Returns:
The transformed quaternion in [x, y, z, w] format.
- Return type:
List
- pyrcareworld.utils.rfuniverse_utility.UnityQuaternionToEular(quaternion: list) list[source]#
Transform quaternion to euler angle in Unity.
- Parameters:
quaternion β List of length 4, representing quaternion in [x, y, z, w]
order.
- Returns:
The transformed euler angle in [x, y, z] order and measured in degree.
- Return type:
List