Helper Functions

Module: cutoop.utils.

Common Helpers

functionmock_time​(fmt: str, logger: Logger | None = None, use_print = False, debug = False)

Record time usage.

Parameters:

  • fmt – info print format
  • use_print – use print instead of logger.info to display information
  • logger – specify logger. Defaults to the 'timer' logger of root .
  • debug – logging using debug level instead of info level.

Usage:

with mock_time("action took %.4fs"):
    # some heavy operation
    pass
functionpool_map​(func: Callable[[...], _R], items: list, processes = 8, use_tqdm = True, desc = 'pool map'): list[_R]

Thread pooling version of map . Equivalent to map(func, items) , except that the argument should be a list (implementing __len__ ) instead of an iterator.

Parameters:

  • processes – number of threads.
  • use_tqdm – whether to display a tqdm bar.
  • desc – set the title of tqdm progress bar if use_tqdm is set.
>>> def square(x):
...     return x * x
>>> cutoop.utils.pool_map(square, list(range(10)))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
functionsave_pctxt​(file: str, pts: ndarray, rgb: None | ndarray = None, normal: None | ndarray = None)

Save point cloud array to file.

Parameters:

  • pts – point cloud array with shape (n, 3)
  • file – dest file name
  • rgb – optional rgb data with shape (n, 3), conflicting with normal . The result format would be X Y Z R G B for one line.
  • normal – optional normal data with shape (n, 3), conflicting with rgb . The result format would be X Y Z NX NY NZ for one line.

Visualization Helpers

functiondraw_bboxes​(img, projected_bbox_Nx2, transformed_bbox_Nx3, color = None, thickness = 1)

Parameters: color – can be a 3-element array/tuple.

functiondraw_text​(img: ndarray, text: str, pos: ndarray): ndarray

draw black text with red border

functiondraw_object_label​(img: ndarray, intrinsics: CameraIntrinsicsBase, sRT_4x4: ndarray, label: str): ndarray

draw label text at the center of the object.

Returns: The image with drawn object label.

functiondraw_3d_bbox​(img: ndarray, intrinsics: CameraIntrinsicsBase, sRT_4x4: ndarray, bbox_side_len: list[float], color = None, thickness = 1): ndarray

Visualize predicted 3D bounding box.

Parameters: color – See draw_bboxes() .

Returns: The image with drawn bounding box.

functiondraw_pose_axes​(img: ndarray, intrinsics: CameraIntrinsicsBase, sRT_4x4: ndarray, length: float, thickness = 1): ndarray

Visualize predicted pose. The XYZ axes are colored by RGB respectively.

Returns: The image with drawn pose axes.