l5kit.rasterization.box_rasterizer module

class l5kit.rasterization.box_rasterizer.BoxRasterizer(render_context: l5kit.rasterization.render_context.RenderContext, filter_agents_threshold: float, history_num_frames: int, render_ego_history: bool = True)

Bases: l5kit.rasterization.rasterizer.Rasterizer

num_channels() int
rasterize(history_frames: numpy.ndarray, history_agents: List[numpy.ndarray], history_tl_faces: List[numpy.ndarray], agent: Optional[numpy.ndarray] = None) numpy.ndarray

Generate raster image by rendering Ego & Agents as bounding boxes on the raster image. Ego & Agents from different past frame are rendered at different image channel.

Parameters
  • history_frames – A list of past frames to be rasterized

  • history_agents – A list of agents from past frames to be rasterized

  • history_tl_faces – A list of traffic light faces from past frames to be rasterized

  • agent – The selected agent to be rendered as Ego, if it is None the AV will be rendered as Ego

Returns

An raster image of size [2xN] with Ego & Agents rendered as bounding boxes, where N is number of history frames

to_rgb(in_im: numpy.ndarray, **kwargs: dict) numpy.ndarray

This function is used to get an rgb image where agents further in the past have faded colors.

Parameters
  • in_im – The output of the rasterize function

  • kwargs – This can be used for additional customization (such as colors)

Returns

An RGB image with agents and ego coloured with fading colors

l5kit.rasterization.box_rasterizer.draw_boxes(raster_size: Tuple[int, int], raster_from_world: numpy.ndarray, agents: numpy.ndarray, color: Union[int, Tuple[int, int, int]]) numpy.ndarray

Draw multiple boxes in one sweep over the image. Boxes corners are extracted from agents, and the coordinates are projected on the image space. Finally, cv2 draws the boxes.

Parameters
  • raster_size – Desired output raster image size

  • raster_from_world – Transformation matrix to transform from world to image coordinate

  • agents – An array of agents to be drawn

  • color – Single int or RGB color

Returns

the image with agents rendered. A RGB image if using RGB color, otherwise a GRAY image

l5kit.rasterization.box_rasterizer.get_box_world_coords(agents: numpy.ndarray) numpy.ndarray

Get world coordinates of the 4 corners of the bounding boxes

Parameters

agents – agents array of size N with centroid (world coord), yaw and extent

Returns

array of shape (N, 4, 2) with the four corners of each agent

l5kit.rasterization.box_rasterizer.get_ego_as_agent(frame: numpy.ndarray) numpy.ndarray

Get a valid agent with information from the AV. Ford Fusion extent is used.

Parameters

frame – The frame from which the Ego states are extracted

Returns

An agent numpy array of the Ego states