How to modify OSD params in Python ds5.0 (NvOSD_RectParams)

  • Docker image : nvcr.io/nvidia/deepstream:5.0-dp-20.04-samples

I have a pipeline with nvmultistreamtiler and nvosd, similar to the deepstream_test_3.py example, and I have the following probe on tiler src pad.

I want to modify the parameters of the objects being overlayed. For example, the detection rectangles should have a width of 1 instead of the default (??) that seems a bit too thick.

The problem is that my probe does not have any effect on the rectangles. Moreover, I suspect it gets access to dummy objects instead of the real ones, because it prints empty values (see code comments) instead of the labels (“Car”, “Person”, etc…)

def on_tiler_src_buffer_probe(self, pad, info):
        gst_buffer = info.get_buffer()
        if not gst_buffer:
            self.log('ERROR: Cannot get GstBuffer')
            return

        batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
        frame_list = batch_meta.frame_meta_list

        if frame_list is not None:
            display_meta = pyds.nvds_acquire_display_meta_from_pool(batch_meta)

            for text in display_meta.text_params:
                print(pyds.get_string(text.display_text)) # prints "None" 16 times per probe call

            for rect in display_meta.rect_params:
                rect.border_width = 1
                print((rect.left, rect.top)) # prints "(0.0, 0.0)" 16 times per probe call

          frame_meta = pyds.NvDsFrameMeta.cast(frame_list.data)
          pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)

      return Gst.PadProbeReturn.OK

OK I found my mistake, this is normal behavior of library.
pyds.nvds_acquire_display_meta_from_pool should only be needed for drawing additional stuff, so it does indeed return empty objects that must be populated accordingly.

In order to modify existing detection boxes, we must iterate frame_meta.obj_meta_list. Each detection object meta has obj_meta.rect_params and obj_meta.text_params that are already pre-computed and can be modified to change the OSD behavior.

One additional problem now is that I can’t make rectangles transparent.

obj_meta.rect_params.border_color.set(0, 1, 0, 0.1)

This code makes bounding boxes green (as expected) but alpha opacity is still 1 (instead of 0.1).

Could anyone confirm please whether it’s possible to have transparent rectangles or not?

+1. I think this is a bug, and it was already the case on Deepstream 4.0.
Some parameters of OSD structs are just not working.

Also, I can confirm that alpha works for obj_meta.rect_params.bg_color (background color). It’s just the border that ignores the alpha value.

This is actually working as expected. Is there a need for the border to also honor alpha setting?

Yes there is a real need for the border to honor alpha setting. For example, when we want a thick border, if it’s not transparent then it’s occluding too much of the object / background in the image.

Even with border width = 1 (which is the minimum) I find it’s too thick, certainly more than 1 pixel thick, and we sometimes cannot observe certain details behind.

And without control of the blending mode, it’s impossible to work around by using 2 rectangles to achieve a border, because the background is obviously a changing image.

I checked and this has not been addressed in DS 5.0 GA.