pyrcareworld.utils package

Contents

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.get_census(img, wsize=7)[source]#
pyrcareworld.utils.active_depth_generate.pad_lr(img: ndarray, ndisp: int) 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.active_depth_generate.unpad_lr(img: ndarray, ndisp: int) ndarray[source]#

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: object

Coordinate 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.

matrix_to_quat(matrix) list[source]#

Convert rotation matrix to quaternion.

Parameters:

matrix – List or np.ndarray shape [3, 3], rotation matrix.

Returns:

List of length 4, quaternion [x, y, z, w].

quat_to_matrix(quat=[0, 0, 0, 1]) ndarray[source]#

Convert quaternion to rotation matrix.

Parameters:

quat – List of length 4, quaternion [x, y, z, w].

Returns:

np.ndarray shape [3, 3], rotation matrix.

pyrcareworld.utils.depth_processor module#

pyrcareworld.utils.interpolate_utils module#

pyrcareworld.utils.locker module#

class pyrcareworld.utils.locker.Locker(lck_name: str)[source]#

Bases: object

pyrcareworld.utils.locker.lock(fp)[source]#
pyrcareworld.utils.locker.unlock(fp)[source]#

pyrcareworld.utils.os_utils module#

pyrcareworld.utils.os_utils.get_eval_file_name(model_dir, eval_file_prefix)[source]#
pyrcareworld.utils.os_utils.make_sb3_model_dir(model_dir)[source]#

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

close()[source]#
online()[source]#
read_bool(datas: bytes) bool[source]#
read_bytes(datas: bytes) bytes[source]#
read_float(datas: bytes) float[source]#
read_int(datas: bytes) int[source]#
read_object(datas: bytes) object[source]#
read_string(datas: bytes) str[source]#
receive_bytes()[source]#
receive_object(data: bytes) list[source]#
receive_step()[source]#
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.

send_bytes(data: bytes)[source]#
send_object(*args)[source]#
sync_step()[source]#
write_bool(datas: bytearray, b: bool)[source]#
write_bytes(datas: bytearray, b: bytes)[source]#
write_float(datas: bytearray, f: float)[source]#
write_int(datas: bytearray, i: int)[source]#
write_object(datas: bytearray, obj)[source]#
write_string(datas: bytearray, s: str)[source]#

pyrcareworld.utils.rfuniverse_utility module#

pyrcareworld.utils.rfuniverse_utility.CheckKwargs(kwargs: dict, compulsory_params: list)[source]#
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

pyrcareworld.utils.version module#

class pyrcareworld.utils.version.Version(version_string: str)[source]#

Bases: object

static sorted(versions: list, reverse=False)[source]#
toString()[source]#

Module contents#