AnnotationContext

Annotation Contexts are metadata providing information to the Rerun viewer on how to interpret and display other entities. Currently, three types of annotations are supported:

  • Labels and/or colors for Rect2D and Box3D entities. These are mapped to the rectangle and box entities via their class_id components. Commonly used for object detection.
  • Labels and/or colors for segmentation images. These are mapped to the images' pixel values, which are interpreted as class_ids.
  • Labels, colors, and/or connections for Point2D and Point3D entities. These are mapped to the point entities via their class_id and keypoint_id components. Commonly used for keypoint or pose detection.

See the Annotation Context concept page for more information.

Components and APIs

Primary component: annotation_context

Python APIs: log_annotation_context

Rust API: AnnotationContext

Rectangles example

import rerun as rr rr.init("rerun_example_annotation_context_rects", spawn=True) # Log an annotation context to assign a label and color to each class rr.log_annotation_context( "/", [ rr.ClassDescription(info=rr.AnnotationInfo(1, "red", (255, 0, 0))), rr.ClassDescription(info=rr.AnnotationInfo(2, "green", (0, 255, 0))), ], ) # Log a batch of 2 rectangles with different `class_ids` rr.log_rects("detections", [[-2, -2, 3, 3], [0, 0, 2, 2]], class_ids=[1, 2], rect_format=rr.RectFormat.XYWH) # Log an extra rect to set the view bounds rr.log_rect("bounds", [0, 0, 5, 5], rect_format=rr.RectFormat.XCYCWH)

Segmentation example

import numpy as np import rerun as rr rr.init("rerun_example_annotation_context_segmentation", spawn=True) # Create a simple segmentation image image = np.zeros((200, 300), dtype=np.uint8) image[50:100, 50:120] = 1 image[100:180, 130:280] = 2 # Log an annotation context to assign a label and color to each class rr.log_annotation_context( "segmentation", [ rr.ClassDescription(info=rr.AnnotationInfo(1, "red", (255, 0, 0))), rr.ClassDescription(info=rr.AnnotationInfo(2, "green", (0, 255, 0))), ], ) rr.log_segmentation_image("segmentation/image", np.array(image))

Connections example

import rerun as rr rr.init("rerun_example_annotation_context_connections", spawn=True) rr.log_annotation_context( "/", rr.ClassDescription( keypoint_annotations=[ rr.AnnotationInfo(0, "zero", (255, 0, 0)), rr.AnnotationInfo(1, "one", (0, 255, 0)), rr.AnnotationInfo(2, "two", (0, 0, 255)), rr.AnnotationInfo(3, "three", (255, 255, 0)), ], keypoint_connections=[(0, 2), (1, 2), (2, 3)], ), ) rr.log_points( "points", [ (0, 0, 0), (50, 0, 20), (100, 100, 30), (0, 50, 40), ], keypoint_ids=[0, 1, 2, 3], )