cv2_visualizer

class real_robot.utils.visualization.cv2_visualizer.CV2Visualizer(window_name='Images', *, update_drawing_fn: Callable[[ndarray, dict[str, ndarray]], tuple[ndarray, Any]] | None = None, run_as_process=False, stream_camera=False)[source]

Bases: object

OpenCV visualizer for RGB and depth images, fps is updated in window title

class DrawingMode(value)[source]

Bases: Enum

Drawing mode when draw_with_mouse()

Box = 0
Point = 1
box_labels: np.ndarray = array([], dtype=int64)
boxes: np.ndarray = array([], shape=(0, 4), dtype=int64)
call_update_drawing_fn() None[source]

Call self._update_drawing_fn with current drawings This happens when the user adds/removes any drawing.

clear_image()[source]

Show a black image

close()[source]
draw_with_mouse(*, update_drawing_fn: Callable[[ndarray, dict[str, ndarray]], tuple[ndarray, Any]] | None = None) tuple[ndarray, dict[str, ndarray], Any] | None[source]

Enter drawing mode with mouse

Parameters:

update_drawing_fn – function to be called with the image and drawn points/boxes. Inputs to this function are an RGB image and a dictionary of {“points”: np.ndarray, “point_labels”: np.ndarray, “boxes”: np.ndarray, “box_labels”: np.ndarray} Outputs are the modified image and any additional data.

Returns:

Original image before drawing, drawn labels dict, _extra_ret_data returned from self._update_drawing_fn()

property drawn_labels: dict[str, ndarray]
static get_image_layout(n_image: int) tuple[int, int][source]

Get layout of Images (n_rows, n_cols) where n_rows >= n_cols

image_boundaries: np.ndarray = array([], shape=(0, 2, 2), dtype=float64)
images: list[np.ndarray] = []
on_mouse(event: int, x: int, y: int, flags: int, param: Any | None = None)[source]

Callback function for mouse events.

Parameters:
point_labels: np.ndarray = array([], dtype=int64)
points: np.ndarray = array([], shape=(0, 2), dtype=int64)
static preprocess_image(image: ndarray, depth_scale=1000.0) ndarray[source]

Preprocess image for plotting with cv2 (RGB2BGR, applyColorMap for depth) :param image: depth, grayscale or RGB color image :param depth_scale: used to apply color map on np.floating depth_image :return image: color image in BGR format, [H, W, 3] np.uint8 np.ndarray

render()[source]

Update renderer to show image and respond to mouse and keyboard events

static resize_image(image: ndarray, max_H: int, max_W: int, interpolation=6) ndarray[source]

Resize image to the requested size while preserving its aspect ratio

run_as_process()[source]

Run CV2Visualizer as a separate process

selected_image_idx: int | None = None
show_images(images: list[ndarray])[source]

Show the list of images, support non-equal size (cv2.rerize to max size)

Parameters:

images – List of np.ndarray images. Supports depth or RGB color images. If depth image, dtype can be np.uint16 or np.floating If RGB image, dtype must be np.uint8