How to use pyds with custom Object classes?

I have a DeepStream 5 application in C/C++ (deepstream-app) where I added some custom classes to the Schema (NvDsVehicleObject → MyObject). I then recompiled the libs and was able to use the new classes in my code and the msg conv and msg broker.

Now I try to do this in pyds, but as it seems the classes are hardcoded into the bindings? (Vehicle, Person, Face, …). To generate my custom msg meta I have to cast an object to my own like so:

obj = pyds.NvDsVehicleObject.cast(data)

as described in python test-app 4

Is creating custom objects possible at all in Python at the moment? The sources are not open, so I could recompile myself, right?

Can I use

Generic buffer: alloc_buffer(size)

with the correct size of a python object to allocate my custom objects from python code?

Thanks for your help!

Can someone help me figure this out? I want to try to create a custom message meta as stated in the README of python test-app 4:

Generating custom metadata for different type of objects:
In addition to common fields provided in NvDsEventMsgMeta structure, user can
also create custom objects and attach to buffer as NVDS_META_EVENT_MSG metadata.
To do that NvDsEventMsgMeta provides "extMsg" and "extMsgSize" fields. User can
create custom structure, fill that structure and assign the pointer of that
structure as "extMsg" and set the "extMsgSize" accordingly.
If custom object contains fields that can't be simply mem copied then user should
also provide function to copy and free those objects.

Refer generate_event_msg_meta() to know how to use "extMsg" and "extMsgSize"
fields for custom objects and how to provide copy/free function and attach that
object to buffer as metadata.

Therefore I created a simple python class with one member:

class MyObject:     
    def __init__(self, num):
         self.num = num

and I want to assign an instance of this to the meta.extMsg:

# set the values of the meta object
meta.type = pyds.NvDsEventType.NVDS_EVENT_CUSTOM
meta.objType = 42
meta.objClassId = 42

# create the meta extension object and set its obj
obj = MyObject(42)
obj_size = sys.getsizeof(obj)

# allocate a c buffer and assign the pointer address
meta.extMsg = pyds.alloc_buffer(obj_size)
meta.extMsgSize = obj_size

But this will only allocate empty memory without a reference to “obj”. How can I write it to the pointer address?

Sadly there is no documentation at all on how to use custom objects. I searched the Github and “alloc_buffer” is only used for a timestamp and not for python objects.

I found similar issuse in the forum now and the suggestion is to create the classes in CPP and then regenerat the bindings.
I already have the structs for the C Version of my project. How do I re-generate the pyds bindings which contain my classes now? I thought the was a closed-source pre compiled lib?

Great! could you take a look DeepStream SDK FAQ - #16 by bcao if it can help you?

this definitly helped a lot. But I still need to know, how to alloc an object, which is not deleted by the python garbage collector. Both examples only cast an existing object to a custom type. I want to set the extMsg to my custom type.

I would like to alloc a new objects on the Cpp Heap.

Would this Binding create a reference, which is maintained after the python code finished?:

 .def_static("cast",[  ](void *data){                 
    return (MyObject*)data;