OSD bbox color change based on custom condition

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) - DGPU
• DeepStream Version 6.2
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only) 525.125.06
• Issue Type( questions, new requirements, bugs) Clarification
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing) It can be reproduced in any Deepstream_test apps.
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

I am using back-to-back detector sample as my base application.

In that I need to change the bbox color based on PGIE and SGIE detection. I tried so many ways and there is no success. There are sample codes for previous versions of Deepstream and I cannot find for 6.2.

static GstPadProbeReturn
nvvidconv_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)
{
GstBuffer *buf = (GstBuffer *) info->data;
NvDsObjectMeta *obj_meta = NULL;
guint vehicle_count = 0;
guint person_count = 0;
gfloat confidence = 0.0;
float border_width = 0.0;
guint64 Object_id_1 = 0;
guint64 Object_id_2 = 0;
char *Object_label = “Empty”;
guint face_count = 0;
guint lp_count = 0;
NvDsMetaList * l_frame = NULL;
NvDsMetaList * l_obj = NULL;
NvDsDisplayMeta *display_meta = NULL;
/*NvDsComp_BboxInfo *org_bbox_coords = NULL; */
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);

for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
  l_frame = l_frame->next) {
    NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
    int offset = 0;
    for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
            l_obj = l_obj->next) {
        obj_meta = (NvDsObjectMeta *) (l_obj->data);

        /* Check that the object has been detected by the primary detector
         * and that the class id is that of vehicles/persons. */
        if (obj_meta->unique_component_id == PRIMARY_DETECTOR_UID) {
          if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE)
            vehicle_count++;
            confidence = obj_meta->confidence;
            Object_id_1 = obj_meta->object_id;
            
          if (obj_meta->class_id == PGIE_CLASS_ID_PERSON)
            person_count++;
            
        }

        if (obj_meta->unique_component_id == SECONDARY_DETECTOR_UID) {
          if (obj_meta->class_id == SGIE_CLASS_ID_FACE) {
            face_count++;

            /* Print this info only when operating in secondary model. */
            if (SECOND_DETECTOR_IS_SECONDARY)
              g_print ("Face found for parent object %p (type=%s)\n",
                  obj_meta->parent, pgie_classes_str[obj_meta->parent->class_id]);
          }
          if (obj_meta->class_id == SGIE_CLASS_ID_LP) {
            lp_count++;
            Object_id_2 = obj_meta->object_id;
            Object_label = obj_meta->obj_label;
            /* Print this info only when operating in secondary model. */
            if (SECOND_DETECTOR_IS_SECONDARY)
              g_print ("License plate found for parent object %p (type=%s)\n",
                  obj_meta->parent, pgie_classes_str[obj_meta->parent->class_id]);
          }
        }
    }
    display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
    NvOSD_TextParams *txt_params  = &display_meta->text_params[0];
    NvOSD_RectParams *rect_params  = &display_meta->rect_params[0];

    display_meta->num_labels = 1;
    txt_params->display_text = g_malloc0 (MAX_DISPLAY_LEN);
    offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, "Person = %d ", person_count);
    offset += snprintf(txt_params->display_text + offset , MAX_DISPLAY_LEN, "Vehicle = %d ", vehicle_count);
    offset += snprintf(txt_params->display_text + offset , MAX_DISPLAY_LEN, "Face = %d ", face_count);
    offset += snprintf(txt_params->display_text + offset , MAX_DISPLAY_LEN, "License Plate = %d ", lp_count);

    /* Now set the offsets where the string should appear */
    txt_params->x_offset = 10;
    txt_params->y_offset = 12;

    /* Font , font-color and font-size */
    txt_params->font_params.font_name = "Serif";
    txt_params->font_params.font_size = 10;
    txt_params->font_params.font_color.red = 1.0;
    txt_params->font_params.font_color.green = 1.0;
    txt_params->font_params.font_color.blue = 1.0;
    txt_params->font_params.font_color.alpha = 1.0;

    /* Text background color */
    txt_params->set_bg_clr = 1;
    txt_params->text_bg_clr.red = 0.0;
    txt_params->text_bg_clr.green = 0.0;
    txt_params->text_bg_clr.blue = 0.0;
    txt_params->text_bg_clr.alpha = 1.0;
     

    rect_params->border_color.red = 0.0;
    rect_params->border_color.green = 0.0;
    rect_params->border_color.blue = 1.0;
    rect_params->border_color.alpha = 1.0;
    rect_params->left  = 10.0;
    rect_params->top  = 10.0;
    rect_params->width  = 450.0;
    rect_params->height  = 460.0;
    rect_params->border_width  = 5.0;
    rect_params->has_bg_color = 1;
    rect_params->bg_color.red = 0.0;
    rect_params->bg_color.green = 0.0;
    rect_params->bg_color.blue = 1.0;
    rect_params->bg_color.alpha = 1.0;       
    border_width = display_meta->num_rects;
    nvds_add_display_meta_to_frame(frame_meta, display_meta);
}


g_print ("Frame Number = %d Vehicle Count = %d Person Count = %d"
        " Face Count = %d License Plate Count = %d  Confidence = %f  Object ID = %ld , %ld, Label = %s , Width = %f \n",
        frame_number, vehicle_count, person_count,
        face_count, lp_count, confidence, Object_id_1, Object_id_2, Object_label, border_width);
frame_number++;
return GST_PAD_PROBE_OK;

}
back_to_back_detectors.c (18.8 KB)

primary_detector_config.txt (2.8 KB)
secondary_detector_config.txt (3.1 KB)
tracker_config.txt (2.1 KB)

NVIDIA-SMI output:
Tue Jul 18 07:47:21 2023
±----------------------------------------------------------------------------+
| NVIDIA-SMI 525.125.06 Driver Version: 525.125.06 CUDA Version: 12.0 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce … On | 00000000:01:00.0 On | N/A |
| 0% 43C P8 12W / 285W | 448MiB / 12282MiB | 2% Default |
| | | N/A |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1252 G /usr/lib/xorg/Xorg 35MiB |
| 0 N/A N/A 1811 G /usr/lib/xorg/Xorg 137MiB |
| 0 N/A N/A 1937 G /usr/bin/gnome-shell 29MiB |
| 0 N/A N/A 2298 G …mviewer/tv_bin/TeamViewer 3MiB |
| 0 N/A N/A 3751 G …RendererForSitePerProcess 45MiB |
| 0 N/A N/A 5563 G /usr/lib/firefox/firefox 183MiB |
±----------------------------------------------------------------------------+

Please help me to fix the issue.

Thank you.

If you want to change the bbox color, please get the bbox rectangle parameter from object meta. NVIDIA DeepStream SDK API Reference: _NvDsObjectMeta Struct Reference | NVIDIA Docs

The attached code just change the bbox color for vehicles.
back_to_back_detectors.c (12.5 KB)

Thank you so much, it works.

Regards,
P. Gnanavelu

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