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:
objectOpenCV visualizer for RGB and depth images, fps is updated in window title
- class DrawingMode(value)[source]¶
Bases:
EnumDrawing 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.
- 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()
- 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)¶
- on_mouse(event: int, x: int, y: int, flags: int, param: Any | None = None)[source]¶
Callback function for mouse events.
- Parameters:
event – one of the cv2.MouseEventTypes: [EVENT_MOUSEMOVE, EVENT_LBUTTONDOWN, EVENT_RBUTTONDOWN, EVENT_MBUTTONDOWN, EVENT_LBUTTONUP, EVENT_RBUTTONUP, EVENT_MBUTTONUP, EVENT_LBUTTONDBLCLK, EVENT_RBUTTONDBLCLK, EVENT_MBUTTONDBLCLK, EVENT_MOUSEWHEEL, EVENT_MOUSEHWHEEL] https://docs.opencv.org/4.9.0/d0/d90/group__highgui__window__flags.html#ga927593befdddc7e7013602bca9b079b0
x – The x-coordinate of the mouse event.
y – The y-coordinate of the mouse event.
flags – one of the cv2.MouseEventFlags: [EVENT_FLAG_LBUTTON, EVENT_FLAG_RBUTTON, EVENT_FLAG_MBUTTON, EVENT_FLAG_CTRLKEY, EVENT_FLAG_SHIFTKEY, EVENT_FLAG_ALTKEY] https://docs.opencv.org/4.9.0/d0/d90/group__highgui__window__flags.html#gaab4dc057947f70058c80626c9f1c25ce
param – The optional user data passed by cv2.setMouseCallback().
- 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