Remove nvdspreprocess's ROI bounding box

I’m trying to remove nvdspreprocess’s ROI bounding box. The green bounding boxes.

preprocess configs

[group-0]
src-ids=-1
custom-input-transformation-function=CustomAsyncTransformation
process-on-roi=0

Code that removes ROI.

if (user_meta->base_meta.meta_type == NVDS_PREPROCESS_BATCH_META) {
      GstNvDsPreProcessBatchMeta* preprocess_batchmeta =
          (GstNvDsPreProcessBatchMeta*)(user_meta->user_meta_data);
      for (auto& roi_meta : preprocess_batchmeta->roi_vector) {
        NvDsFrameMeta* frame_meta = roi_meta.frame_meta;

        NvOSD_RectParams& roi = roi_meta.roi;
        roi.border_width = 0;
        roi.width = 0;
        roi.height = 0;

        NvDsDisplayMeta* display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
        nvds_add_display_meta_to_frame(frame_meta, display_meta);
...

I followed deepstream_preprocess_test.cpp app. If you want to try, please try it in this sample app.

Architecture: x86_64
GPU: NVIDIA GeForce GTX 1650 Ti with Max-Q Design
NVIDIA GPU Driver: Driver Version: 495.29.05
DeepStream Version: 6.0 (running on docker image nvcr.io/nvidia/deepstream:6.0-devel)
TensorRT Version: v8001
Issue Type: Question

Thanks
Peeranat F.

.

Do you meet any issue for removing the ROI bounding box?

The question concerns the ROI bounding boxes introduced by the nvdspreprocess module (the two green boxes in both streams). I’m sorry I’m not sure what ROI bounding boxes are you talking about? In the screenshot, there are only 2 green ROI bounding boxes.

The nvdspreprocess is open source. You can find the macro DRAW_ROIS in the code.

Within the macro DRAW_ROIs in gstnvdspreprocess.cpp,

#ifdef DRAW_ROIS
          NvDsDisplayMeta *display_meta = nvds_acquire_display_meta_from_pool (batch_meta);
          display_meta->num_rects = 1;
          display_meta->rect_params[0].left = rect_params.left;
          display_meta->rect_params[0].top = rect_params.top;
          display_meta->rect_params[0].width = rect_params.width;
          display_meta->rect_params[0].height = rect_params.height;
          display_meta->rect_params[0].border_width = 2;
          display_meta->rect_params[0].border_color = {0,1,0,1};

          nvds_add_display_meta_to_frame(frame_meta, display_meta);
#endif

num_rects is set to 1. But when I printed display data

NvDsDisplayMeta* display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
auto& rect = display_meta->rect_params[0];
g_print("rect_params = num_rects: %d, (width, height): (%f, %f)\n", display_meta->num_rects, rect.border_width, rect.width, rect.height);
# outputs rect_params = num_rects: 0, (width, height): (0.000000, 0.000000)

NvOSD_RectParams& roi = roi_meta.roi;
g_print("roi = (width, height): (%f, %f)\n", roi.width, roi.height);
# outputs roi = (width, height): (1088.000000, 608.000000)

Did I miss something?

Please remove your own code too.

@peeranat85 in order to avoid displaying the ROI for the full-frame source(where process-on-roi=0)

You can modify the gstnvdspreprocess.cpp app like

#ifdef DRAW_ROIS
// updating display meta to draw roi rectangle
if (preprocess_group->process_on_roi){
NvDsDisplayMeta *display_meta = nvds_acquire_display_meta_from_pool (batch_meta);
display_meta->num_rects = 1;
display_meta->rect_params[0].left = rect_params.left;
display_meta->rect_params[0].top = rect_params.top;
display_meta->rect_params[0].width = rect_params.width;
display_meta->rect_params[0].height = rect_params.height;
display_meta->rect_params[0].border_width = 2;
display_meta->rect_params[0].border_color = {0,1,0,1};
nvds_add_display_meta_to_frame(frame_meta, display_meta);
}
#endif

Where we are making sure that Display meta is added only for the source for which the process_on_roi is enabled.

@Fiona.Chen I have removed all my code. Here, it contains only what I showed you previously.

static GstPadProbeReturn pgie_src_pad_buffer_probe(GstPad* pad, GstPadProbeInfo* info,
                                                   gpointer u_data) {
  NvDsBatchMeta* batch_meta = gst_buffer_get_nvds_batch_meta(GST_BUFFER(info->data));

  for (NvDsMetaList* l_user_meta = batch_meta->batch_user_meta_list; l_user_meta != NULL;
       l_user_meta = l_user_meta->next) {
    NvDsUserMeta* user_meta = (NvDsUserMeta*)(l_user_meta->data);

    if (user_meta->base_meta.meta_type == NVDS_PREPROCESS_BATCH_META) {
      GstNvDsPreProcessBatchMeta* preprocess_batchmeta =
          (GstNvDsPreProcessBatchMeta*)(user_meta->user_meta_data);
      for (auto& roi_meta : preprocess_batchmeta->roi_vector) {
        NvDsFrameMeta* frame_meta = roi_meta.frame_meta;
        NvDsDisplayMeta* display_meta = nvds_acquire_display_meta_from_pool(batch_meta);

        auto& rect = display_meta->rect_params[0];
        g_print("rect_params = num_rects: %d, (width, height): (%f, %f)\n", display_meta->num_rects, rect.border_width, rect.width, rect.height);
        NvOSD_RectParams& roi = roi_meta.roi;
        g_print("roi = (width, height): (%f, %f)\n", roi.width, roi.height);
        nvds_add_display_meta_to_frame(frame_meta, display_meta);

      }        // ROI
    }          // NVDS_PREPROCESS_BATCH_META
  }            // NvDsMetaList

  return GST_PAD_PROBE_OK;
}

the result is still the same

rect_params = num_rects: 0, (width, height): (0.000000, 0.000000)
roi = (width, height): (1088.000000, 608.000000)

@vishkumar thank you for ur response. I prefer to modify the display from my side instead of messing with DeepSteram source code if possible.

Thanks

Do you know what the nvds_acquire_display_meta_from_pool() function mean?NVIDIA DeepStream SDK API Reference: Metadata Structures

You required a new NvDsDisplayMeta, so the values in this data structure are all zero.
Please make sure you understand what you are doing by read documents and sample codes.

@Fiona.Chen thank you. I’ve found the solution.

for (NvDsMetaList* l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next) {
    NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
    NvDisplayMetaList *display_meta_list;

    for (NvDisplayMetaList* l_display = frame_meta->display_meta_list; l_display != NULL; l_display = l_display->next) {
      NvDsDisplayMeta* display_meta = (NvDsDisplayMeta*)(l_display->data);
      display_meta->num_rects = 0;
      auto& rect = display_meta->rect_params[0];
      g_print("before rect_params = num_rects: %d, (width, height): (%f, %f)\n", display_meta->num_rects, rect.width, rect.height);
      rect.left = 0;
      rect.top = 0;
      rect.width = 0;
      rect.height = 0;
      rect.border_width = 0;
      g_print("after rect_params = num_rects: %d, (width, height): (%f, %f)\n", display_meta->num_rects, rect.width, rect.height);
    }
  }

yields

before rect_params = num_rects: 0, (width, height): (1088.000000, 608.000000)
after rect_params = num_rects: 0, (width, height): (0.000000, 0.000000)

and the bounding boxes no longer display.

Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.