get_nvds_buf_surface

savant.deepstream.utils.get_nvds_buf_surface(buffer, nvds_frame_meta)

This function returns the frame in NumPy format. Only RGBA format is supported. For x86_64, only unified memory is supported. For Jetson, the buffer is mapped to CPU memory. Changes to the frame image will be preserved and seen in downstream elements, with the following restrictions.

  1. No change to image color format or resolution

  2. No transpose operation on the array.

The function automatically unmaps NvDsBufSurface to prevent memory leak. See https://github.com/insight-platform/Savant/issues/25 for the details.

Usage example:

with get_nvds_buf_surface(buffer, nvds_frame_meta) as np_frame:
    frame_bytes = np_frame.tobytes()
Parameters:
  • buffer (Buffer) – Gstreamer buffer which contains NvBufSurface.

  • nvds_frame_meta (pyds.NvDsFrameMeta) – NvDs frame metadata which contains frame info.

Returns:

Frame in NumPy format.

Return type:

AbstractContextManager[ndarray]