Can the deepstream python code change the id of the tracked object by itself and display it on the screen?

Please provide complete information as applicable to your setup.

**• Hardware Platform (Jetson / GPU)**Jetson
• DeepStream Version 6.0
**• JetPack Version (valid for Jetson only)**4.6
• TensorRT Version 7.6
• NVIDIA GPU Driver Version (valid for GPU only) GPU
**• Issue Type( questions, new requirements, bugs)**questions

I want to replace the automatically generated tracking id with my own tracking id. How do I implement the code?

Can I modify the data going into nvosd? I look at the code comments indicating that nvosd is the element that draws the box and id

You can connect a probe to the sinkpad of OSD and modify the bbox values as you need.
Check this datastructure NvDsObjectMeta — Deepstream Deepstream Version: 6.1.1 documentation

1 Like

I tried to set all object_ID to 0 but the id that finally appeared on the screen was the same as before the change.

I guess the probe just copies the value in the metadata and can’t be modified?

If you just want to change the text, you modify the text_params property of an object.

Example for a single object:
obj_meta.text_params.display_text = f"ID: {tracking_id}"
where tracking_id is your own tracking ID

I see. Would it be possible to attach your code/pipeline?

test5.py (28.4 KB)

Okay, thank you very much !!!

Yes, you’re right. Even after changing it using obj_meta.object_id it still shows the original.
If it is really needed to change that value, then you can create a copy of that object meta and attach it to the object meta list. But I don’t think it would be very efficient to do that.
You can use this function nvds-acquire-obj-meta-from-pool to create a new NvDsObjectMeta, then assign the properties as you like and attach the meta back to the pool using nvds_add_obj_meta_to_frame

Instead if you just need to view it on screen, you can modify the text parameters to show your tracking ID.
Given below is a minimum usable code for your probe function.

from random import randint
def osd_sink_pad_buffer_probe(pad, info, _):

        buffer = info.get_buffer()
        batch = pyds.gst_buffer_get_nvds_batch_meta(hash(buffer))

        l_frame = batch.frame_meta_list
        while l_frame:
            frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
            l_obj = frame_meta.obj_meta_list
            while l_obj:
                obj_meta = pyds.NvDsObjectMeta.cast(l_obj.data)
                obj_meta.text_params.display_text = f"{randint(10, 1000)}"
                l_obj = l_obj.next
            l_frame = l_frame.next

        return Gst.PadProbeReturn.OK
1 Like

Ok, thank you very much. If you have time, I have two last questions. The first one is where can I find these functions. Can you give me the document address? Because I may also need to hide part of the text later. The second is that the tracker can be set to choose to track a certain category of objects?

Sure, you can find all these methods here Methods — Deepstream Deepstream Version: 6.1.1 documentation
For some reason the nvds_add_obj_meta_to_frame is missing from this document so you can refer to the previous DS version’s C/C++ document instead NVIDIA DeepStream SDK API Reference: Metadata Structures
I can confirm this function exists in DS 6.0 as I have used it before.

For your second question, there is no direct way to track only certain objects, but instead you can set checkClassMatch to true in your tracking config and filter out the objects that you don’t need. This might be helpful Gst-nvtracker — DeepStream 6.1.1 Release documentation

Oh seems there is some example of using those functions to create new objects Modifiyng object meta using python bindings

Ok, thanks for sharing

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