Access to NvDsUserMeta using pybindings

Hi,

I made an application, based on deepstream-test1-app which add NvDsUserMeta on the object level. In the cpp version, I’ve successfully managed to get NvDsUserMeta through this snippet:

 for (l_user_meta = obj_meta->obj_user_meta_list; l_user_meta != NULL;
        l_user_meta = l_user_meta->next) 
{
    user_meta = (NvDsUserMeta *) (l_user_meta->data);
    user_meta_data = (gfloat *)user_meta->user_meta_data;
    if(user_meta->base_meta.meta_type == NVDS_USER_FRAME_META_EXAMPLE)
    {
        g_print("\n************ Retrieving user_meta_data array of 1 on osd sink pad\n");
        for(i = 0; i < 1; i++) {
            g_print("user_meta_data [%d] = %f\n", i, user_meta_data[i]);
        }
        g_print("\n");
    }
}

The NvDsUserMeta is presented as the float array with size 1 (i.e. 1 value).

In the python application, which has to do the same, I’m trying to access NvDsUserMeta as follows:

l_user_meta = obj_meta.obj_user_meta_list
while l_user_meta is not None:
    try:
        user_meta = pyds.glist_get_nvds_user_meta(l_user_meta.data)
 
        print("User meta", user_meta.user_meta_data)
    except StopIteration:
        break

And the output that I got is:

User meta <capsule object NULL at 0x7fa85fdc60>

Can you help me how to get the user_meta_data in a proper way?

1 Like

Hi igreeser, how is your float array attached to user_meta in Python?

Long story short, I’ve modified libnvds_infer.so and libnvdsgst_infer.so. Hence, I’m attaching the NvDsUserMeta on object level in void attach_metadata_detector(...) function in the /opt/nvidia/deepstream/deepstream-4.0/sources/gst-plugins/gst-nvinfer/gstnvinfer_meta_utils.cpp file.

Thanks for the info. We’ll figure out how to bind user defined data generically. If we return a raw buffer of bytes, would you be able to make use of it?

In this particular case, I think yes. Since now the user data is presented as float array. But in case of more complex data structure it might be tricky.

For custom C structs, you can provide your own bindings with a cast function to cast pointer into the struct. You can use Pybind11 or maybe even Ctypes if the pointer deference works. In our bindings, pointers are returned as int (size_t in C). We’ll look into providing an example in our documentation.

1 Like

I am also looking for accessing custom user meta data(array of int) inside python. But I could not find any example for doing this. Is there any new updates? It would be helpful if there is an example app in python like in cpp for user meta data.

Hi mdk,

Please help to open a new topic with more details. Thanks