xrfeitoria.utils.viewer

Utils for loading images and annotations.

class xrfeitoria.utils.viewer.Viewer(sequence_dir: str | Path)[source]

Utils for loading images and annotations.

Examples

>>> viewer = Viewer('/path/to/sequence')
>>> camera_name = 'cam'
>>> frame = 0
>>> img = viewer.get_img(camera_name=camera_name, frame=frame)
>>> mask = viewer.get_mask(camera_name=camera_name, frame=frame)
>>> depth = viewer.get_depth(camera_name=camera_name, frame=frame)
>>> flow = viewer.get_flow(camera_name=camera_name, frame=frame)
>>> normal = viewer.get_normal(camera_name=camera_name, frame=frame)
>>> diffuse = viewer.get_diffuse(camera_name=camera_name, frame=frame)
__init__(sequence_dir: str | Path) None[source]

Initialize with the sequence directory.

Parameters:

sequence_dir (PathLike) – path to the sequence directory

get_depth(camera_name: str, frame: int, depth_rescale=1.0) ndarray[source]

Get depth of the given frame (‘depth/{frame:04d}.*’)

Parameters:
  • camera_name (str) – the camera name

  • frame (int) – the frame number

  • depth_rescale (float, optional) – scaling the depth to map it into (0, 255). Depth values great than depth_rescale will be clipped. Defaults to 1.0.

Returns:

np.ndarray – depth of shape (H, W, 3)

get_diffuse(camera_name: str, frame: int) ndarray[source]

Get diffuse image of the given frame (‘diffuse/{frame:04d}.*’)

Parameters:
  • camera_name (str) – the camera name

  • frame (int) – the frame number

Returns:

np.ndarray – image of shape (H, W, 3)

get_flow(camera_name: str, frame: int) ndarray[source]

Get optical flow of the given frame (‘flow/{frame:04d}.*’)

Parameters:
  • camera_name (str) – the camera name

  • frame (int) – the frame number

  • depth_rescale (float, optional) – scaling the depth to map it into (0, 255). Depth values great than depth_rescale will be clipped. Defaults to 1.0.

Returns:

np.ndarray – optical flow of shape (H, W, 3)

get_img(camera_name: str, frame: int) ndarray[source]

Get rgb image of the given frame (‘img/{frame:04d}.*’)

Parameters:
  • camera_name (str) – the camera name

  • frame (int) – the frame number

Returns:

np.ndarray – image of shape (H, W, 3)

get_mask(camera_name: str, frame: int) ndarray[source]

Get mask of the given frame (‘mask/{frame:04d}.*’)

Parameters:
  • camera_name (str) – the camera name

  • frame (int) – the frame number

Returns:

np.ndarray – image of shape (H, W, 3)

get_normal(camera_name: str, frame: int) ndarray[source]

Get normal map of the given frame (‘normal/{frame:04d}.*’)

Parameters:
  • camera_name (str) – the camera name

  • frame (int) – the frame number

Returns:

np.ndarray – normal map of shape (H, W, 3)

DEPTH = 'depth'
DIFFUSE = 'diffuse'
FLOW = 'flow'
IMG = 'img'
MASK = 'mask'
NORMAL = 'normal'