I need to pass two values calculated in a custom-plugin I’ve made and fetch them with a sink pad buffer probe.
Currently I’m modifying the gst-dsdirection plugin and saving a user_meta to frame_meta. The output is the same DsDirectionOutput as in the gst-dsdirection example.
In the python application I’m fetching it like this:
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.glist_get_nvds_frame_meta()
# 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.glist_get_nvds_frame_meta(l_frame.data)
frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
except StopIteration:
break
l_user = frame_meta.frame_user_meta_list
print(l_user)
user_meta = pyds.NvDsUserMeta.cast(l_user.data)
print('user_meta:', user_meta)
print('user_meta.user_meta_data:', user_meta.user_meta_data)
print('user_meta.base_meta:', user_meta.base_meta)
The output from this is:
...
<pyds.GList object at 0x7f2d8fc10030>
user_meta: <pyds.NvDsUserMeta object at 0x7f2d8fc10ab0>
user_meta.user_meta_data: <capsule object NULL at 0x7f2d8fc6a300>
user_meta.base_meta: <pyds.NvDsBaseMeta object at 0x7f2d8fc100a0>
...
Any idea how to properly add it to the frame_meta and/or fetch the values with the python bindings? Should I maybe save this as a different object structure?
But the main thing is that I’m having trouble fetching the values with a python app (probe).
I’m wondering what is the best way to do this?
I just need to save two floats in my custom plug-in to each frame, and then be able to fetch it in my python app.
However I’m not able to cast it successfully to python with this (added in pyds_tracker_meta.cpp)
m.def("DsDirectionObject2_cast",
[](void *obj) { return (DsDirectionObject2*)(obj); },
"Cast given object/data to DsDirectionObject2",
py::arg("obj"),
py::return_value_policy::reference);
I always get the same error when I try to print the type and cast it to python
while user_meta_list is not None:
user_meta = pyds.NvDsUserMeta.cast(user_meta_list.data)
try:
print('user_meta: ', user_meta.base_meta.meta_type)
if str(user_meta.base_meta.meta_type) != 'NvDsMetaType.NVDS_OPTICAL_FLOW_META':
dsdir = pyds_tracker_meta.DsDirectionObject2_cast(user_meta.user_meta_data)
print('dsdir: ', dsdir)
except Exception as e:
print(e)
user_meta_list = user_meta_list.next
Then the output is:
user_meta: NvDsMetaType.NVDS_OPTICAL_FLOW_META
user_meta: NvDsMetaType.???
Unable to convert function return value to a Python type! The signature was
(obj: capsule) -> DsDirectionObject2
There is no update from you for a period, assuming this is not an issue any more.
Hence we are closing this topic. If need further support, please open a new one.
Thanks
Oh, seems you also need to add binding function for your user meta type, it’s NVDS_DIRECTION_USER_META you defined, right?