# Custom NvDsObjectMeta in Python

**URL:** <https://forums.developer.nvidia.com/t/custom-nvdsobjectmeta-in-python/125690>\
**Category:** DeepStream SDK\
**Created:** [June 1, 2020, 8:55am UTC](https://forums.developer.nvidia.com/t/custom-nvdsobjectmeta-in-python/125690 "2020-06-01T08:55:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ap2565](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ap2565](https://forums.developer.nvidia.com/u/ap2565)\
**Post date:** [June 1, 2020, 8:55am UTC](https://forums.developer.nvidia.com/t/custom-nvdsobjectmeta-in-python/125690/1 "2020-06-01T08:55:48Z")

</div>

Hi, I am trying to adding to add my own NvDsObjectMeta data to the buffer in Python as I am using an external, non TRT model.

In my pipeline I have the following elements (in the order of linking)

```
uridecodebin
streamux
nvvidconv
filter
tracker
sink

```

I have a probe at the sink pad of the filter. Using the following code I am able to extract the decoded frame from the pipeline inside that probe function:

```
def filter1_sink_pad_buffer_probe(self, pad, info, u_data):
    frame_number = 0
    num_rects = 0
    gst_buffer = info.get_buffer()
    if not gst_buffer:
        print("Unable to get GstBuffer ")
        return
    batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
    l_frame = batch_meta.frame_meta_list

    while l_frame is not None:
        try:
            # Note that l_frame.data needs a cast to pyds.NvDsFrameMeta
            # The casting is done by pyds.NvDsFrameMeta.cast()
            # The casting also keeps ownership of the underlying memory
            # in the C code, so the Python garbage collector will leave
            # it alone.
            frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
        except StopIteration:
            print("returning")
            return

        # Retrieve batch metadata from the gst_buffer
        # Note that pyds.gst_buffer_get_nvds_batch_meta() expects the
        # C address of gst_buffer as input, which is obtained with hash(gst_buffer)]
        frame_number = frame_meta.frame_num

        # NVINFER ELEMENT PRODUCES BATCH DATA OF TYPE NVDS_META_FRAME_INFO

        # THE FUNCTION BELOW SUPPORTS RGBA FORMAT ONLY!!!
        n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
        # convert python array into numpy array format.
        self.out_image = np.array(n_frame, copy=True, order='C')

```

This image then gets sent to an inference engine and I receive the detection results (bbox x,y,w,h confidence and class\_id). Now, I fill in the NvDsObjectMeta for each object inside the same probe function:

```
pyds.nvds_acquire_meta_lock(batch_meta)
frame_meta.bInferDone = True
obj_meta = pyds.nvds_acquire_obj_meta_from_pool(batch_meta)
obj_meta.rect_params.top = y - (h / 2)
obj_meta.rect_params.left = x - (w / 2)
obj_meta.rect_params.width = w
obj_meta.rect_params.height = h

obj_meta.parent = None
obj_meta.confidence = confidence
obj_meta.class_id = class_id
UNTRACKED_OBJ_ID = 0xFFFFFFFFFFFFFFFF
obj_meta.object_id = UNTRACKED_OBJ_ID
obj_meta.unique_component_id = 1
pyds.nvds_add_obj_meta_to_frame(frame_meta, obj_meta, None)
pyds.nvds_release_meta_lock(batch_meta)

```

Now when I run my code, everything works fine but it seems like the tracker isn’t updating the NvDsObjectMeta data with updating bbox params? What am I missing?

When I add a probe to the sink of the tracker and print object ID’s I get:

```
trackingId = long_to_int(obj_meta.object_id)
print("TRACKING ID AT TRACKER SINK IS {}".format(trackingId))
**-1**

```

The tracking ID never changes from -1 for any object. Am I supposed to increment this number in my filter probe function or should NvTracker do this?

Thanks

**• Hardware Platform GPU - RTX2060 Super**  
**• DeepStream Version - 5**  
**• NVIDIA GPU Driver Version - 440.64**

---

<div class="post-metadata">

**Author:** ![Amycao](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/amycao/32/11342_2.png) [@Amycao](https://forums.developer.nvidia.com/u/Amycao)\
**Post date:** [June 12, 2020, 10:03am UTC](https://forums.developer.nvidia.com/t/custom-nvdsobjectmeta-in-python/125690/3 "2020-06-12T10:03:33Z")

</div>

Hi  
Sorry for a late reply.  
Can you modify  
obj\_meta.rect\_params.top = y - (h / 2)  
obj\_meta.rect\_params.left = x - (w / 2)  
to  
obj\_meta.rect\_params.top = y  
obj\_meta.rect\_params.left = x  
and try again?  
you do not need to set object\_id, the tracker will do this.

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [October 12, 2021, 4:17pm UTC](https://forums.developer.nvidia.com/t/custom-nvdsobjectmeta-in-python/125690/5 "2021-10-12T16:17:35Z")

</div>

Closed on October 12, 2021, 4:17pm UTC


