Get frame width and height from metadata

I’m trying to modify deepstream-app-main.c to use the frame width and height while processing bounding boxes. I replaced the original all_bbox_generated function with this one:

static void
 all_bbox_generated (AppCtx * appCtx, GstBuffer * buf,
     NvDsBatchMeta * batch_meta, guint index)
 {

   for (NvDsMetaList * l_frame = batch_meta->frame_meta_list; l_frame != NULL;
       l_frame = l_frame->next) {
     NvDsFrameMeta *frame_meta = l_frame->data;
     g_print("frame size %d x %d\n", frame_meta->source_frame_width, frame_meta->source_frame_height);
   }
 }

The resulting output for every frame is:

frame size 0 x 0
frame size 0 x 0
frame size 0 x 0
frame size 0 x 0

Why are these metadata fields not being set? How do I get the overall frame dimensions corresponding to the bounding box coordinates?

please refer to https://docs.nvidia.com/metropolis/deepstream/plugin-manual/index.html#page/DeepStream_Plugin_Manual%2Fdeepstream_plugin_metadata.03.2.html%23wwconnect_header
for an introduction about meta hierarchy, for dimensions about bounding box coordinates, it’s in
NvDsObjectMeta->rect_params
https://docs.nvidia.com/metropolis/deepstream/dev-guide/DeepStream_Development_Guide/baggage/group__metadata__structures.html

Hi, I’m looking for the frame dimensions, not the bounding box coordinates.

as for frame dimensions, see NvBufSurface from sources/includes/nvbufsurface.h

Ok, so NvDsFrameMeta.source_frame_height and .source_frame_width are not used.

The buffer needs to be mapped to a GstMapInfo struct then NvBufSurfaceParams.width and NvBufSurfaceParams.height can be used.

static void
 all_bbox_generated (AppCtx * appCtx, GstBuffer * buf,
     NvDsBatchMeta * batch_meta, guint index)
 {
   for (NvDsMetaList * l_frame = batch_meta->frame_meta_list; l_frame != NULL;
       l_frame = l_frame->next) {
     NvDsFrameMeta *frame_meta = l_frame->data;
     g_print("NvDsFrameMeta.source_frame_width=%d\n", frame_meta->source_frame_width);
     g_print("NvDsFrameMeta.source_frame_height=%d\n", frame_meta->source_frame_height);
   }
 
   GstMapInfo map_info;
   memset(&map_info, 0, sizeof(map_info));
   if (!gst_buffer_map (buf, &map_info, GST_MAP_READ)){
       g_print("Error: Failed to map GST buffer");
   } else {
       NvBufSurface *surface = NULL;
       surface = (NvBufSurface *) map_info.data;
       g_print("NvBufSurfaceParams.width=%d\n", surface->surfaceList[0].width);
       g_print("NvBufSurfaceParams.height=%d\n", surface->surfaceList[0].height);
       gst_buffer_unmap(buf, &map_info);
   }
 
 }

Output:

NvDsFrameMeta.source_frame_width=0
NvDsFrameMeta.source_frame_height=0
NvBufSurfaceParams.width=608
NvBufSurfaceParams.height=480