Access DSANALYTICSFRAME with python

Hi!
I want to access user data with python .
but i can’t make it with python and could make it with c++.
How can i do this with python

    while l_user is not None:
        user_meta = pyds.NvDsUserMeta.cast(l_user.data)
        NVDS_USER_FRAME_META_NVDSANALYTICS = pyds.nvds_get_user_meta_type("NVIDIA.DSANALYTICSFRAME.USER_META")
        #NVDS_USER_FRAME_META_DSANALYTICSOBJ = pyds.nvds_get_user_meta_type("NVIDIA.DSANALYTICSOBJ.USER_META")
        if user_meta.base_meta.meta_type == NVDS_USER_FRAME_META_NVDSANALYTICS:
            meta = user_meta.user_meta_data
            if meta is not None:
                try:
                    string1="LineCrossing Cumulativ:{}".format(meta.objLCCumCnt)
                    print(string1)
                except StopIteration:
                    break
            if meta is not None:
                try:
                    string1="LineCrossing current frame:{}".format(meta.objLCCurrCnt)
                    print(string1)
                    a=1
                except StopIteration:
                    break

• Hardware Platform (Jetson / GPU) : jetson nano
• DeepStream Version : 5.0
• TensorRT Version : 7.0.0-1
• NVIDIA GPU Driver Version (valid for GPU only):

Hi @manaism,
Could you refer to https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/blob/master/apps/deepstream-imagedata-multistream/deepstream_imagedata-multistream.py#L70 ?

Hi! mchi
Thanks your reply.
but i want to access objLCCumCnt or objLCCurrCnt in NvDsAnalyticsFrameMeta.
How could i do with python?

please try describing the issue as clear as possible!

What do you mean “i can’t make it”, does it crash or return invalid valid when you access it ?
objLCCumCnt is element of NvDsAnalyticsFrameMeta, did you run Gst-nvdsanalytics?

Hi @manaism,

Is this still an issue to support? Any status can be updated?

I’m sorry about that.

I make my app that count number of people crossing line with nvdsanalytics api.
I set pipeline and it run well with display.
When i get the data in NvDsAnalyticsFrameMeta, i have this error.
How can i get the data in NvDsAnalyticsFrameMeta by python

This is callback function.

def tiler_sink_pad_buffer_probe(pad,info,u_data):
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:
break

    frame_number = frame_meta.frame_num
    num_rects = frame_meta.num_obj_meta
    l_obj=frame_meta.obj_meta_list
    while l_obj is not None:
        try:
            # Casting l_obj.data to pyds.NvDsObjectMeta
            obj_meta=pyds.NvDsObjectMeta.cast(l_obj.data)
        except StopIteration:
            break
        class_id = obj_meta.class_id
        confidence = round(obj_meta.confidence,3)
        #print("{}'s confidence={}".format(class_id,confidence))
        try: 
            l_obj=l_obj.next
        except StopIteration:
            break
    l_user = frame_meta.frame_user_meta_list

    while l_user is not None:
        user_meta = pyds.NvDsUserMeta.cast(l_user.data)
        NVDS_USER_FRAME_META_NVDSANALYTICS = pyds.nvds_get_user_meta_type("NVIDIA.DSANALYTICSFRAME.USER_META")
        #NVDS_USER_FRAME_META_DSANALYTICSOBJ = pyds.nvds_get_user_meta_type("NVIDIA.DSANALYTICSOBJ.USER_META")
        if user_meta.base_meta.meta_type == NVDS_USER_FRAME_META_NVDSANALYTICS:
            print(user_meta.base_meta.meta_type)
            meta = user_meta.user_meta_data
            if meta is not None:
                try:
                    string1="LineCrossing Cumulativ:{}".format(meta.objLCCumCnt)
                    string2="LineCrossing current frame:{}".format(meta.objLCCurrCnt)
                    print(string1)
                    print(string2)
                except StopIteration:
                    break
        try:
            l_user = l_user.next
        except StopIteration:
            break

    try:
        l_frame=l_frame.next
    except StopIteration:
        break    


return Gst.PadProbeReturn.OK

and i have error below.

raceback (most recent call last):
File “/home/humani/Documents/apc_project/main.py”, line 66, in tiler_sink_pad_buffer_probe
string1=“LineCrossing Cumulativ:{}”.format(meta.objLCCumCnt)
AttributeError: ‘PyCapsule’ object has no attribute ‘objLCCumCnt’

@manaism refer this Deepstream 5.0 python bindings for Gst-nvdsanalytics access meta data