vis4d.vis.image.canvas.base

Base class of canvas for image based visualization.

Classes

CanvasBackend()

Abstract interface that allows to draw on images.

class CanvasBackend[source]

Abstract interface that allows to draw on images.

Supports drawing different bounding boxes on top of an image.

as_numpy_image()[source]

Returns the current canvas as numpy image.

Return type:

ndarray[Any, dtype[uint8]]

create_canvas(image=None, image_hw=None)[source]

Creates a new canvas with a given image or shape internally.

Either provide a background image or the desired height, width of the canvas.

Parameters:
  • image (np.array[uint8] | None) – Numpy array with a background image

  • image_hw (tuple[int, int] | None) – height, width of the canvas

Return type:

None

draw_bitmap(bitmap, color, top_left_corner=(0, 0), alpha=0.5)[source]

Draws a binary mask onto the given canvas.

Parameters:
  • bitmap (ndarray) – The binary mask to draw

  • color (tuple[int, int, int]) – Color of the box [0,255].

  • top_left_corner (tuple(float, float)) – Coordinates of top left corner of the bitmap. Defaults to (0, 0).

  • alpha (float, optional) – Alpha value for transparency of this mask. Defaults to 0.5.

Return type:

None

draw_box(corners, color, width=1)[source]

Draws a box onto the given canvas.

Parameters:
  • corners (list[float]) – Containing [x1,y1,x2,y2] the corners of the box.

  • color (tuple[int, int, int]) – Color of the box [0,255].

  • width (int, optional) – Line width. Defaults to 1.

Raises:

ValueError – If the canvas is not initialized.

Return type:

None

draw_box_3d(corners, color, intrinsics, width=0, camera_near_clip=0.15)[source]

Draws a line between two points.

Parameters:
  • corners (list[tuple[float, float, float]]) – Containing the eight corners of the box.

  • color (tuple[int, int, int]) – Color of the line.

  • intrinsics (NDArrayF32) – Camera intrinsics matrix.

  • width (int, optional) – The width of the line. Defaults to 0.

  • camera_near_clip (float, optional) – The near clipping plane of the camera. Defaults to 0.15.

Return type:

None

draw_circle(center, color, radius=2)[source]

Draw a circle onto canvas.

Parameters:
  • center (tuple[float, float]) – Center of the circle.

  • color (tuple[int, int, int]) – Color of the circle.

  • radius (int, optional) – Radius of the circle. Defaults to 2.

Return type:

None

draw_line(point1, point2, color, width=0)[source]

Draw a line onto canvas from point 1 to 2.

Parameters:
  • point1 (tuple[float, float]) – Start point (2D pixel coordinates).

  • point2 (tuple[float, float]) – End point (2D pixel coordinates).

  • color (ttuple[int, int, int]) – Color of the line.

  • width (int, optional) – Line width. Defaults to 0.

Return type:

None

draw_rotated_box(corners, color, width=0)[source]

Draws a box onto the given canvas.

Corner ordering:

  1. +———+ (3) | | | | | |

  1. +———+ (1)

Parameters:
  • corners (list[tuple[float, float]]) – Containing the four corners of the box.

  • color (tuple[int, int, int]) – Color of the box [0,255].

  • width (int, optional) – Line width. Defaults to 0.

Return type:

None

draw_text(position, text, color=(255, 255, 255))[source]

Draw text onto canvas at given position.

Parameters:
  • position (tuple[float, float]) – x,y position where the text will start.

  • text (str) – Text to be placed at the given location.

  • color (tuple[int, int, int], optional) – Text color. Defaults to (255, 255, 255).

Return type:

None

save_to_disk(image_path)[source]

Writes the current canvas to disk.

Parameters:

image_path (str) – Full image path (with file name and ending).

Return type:

None