Thank you for your answer, I have tried using your solution, which I modified to:
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "/opt/nvidia/deepstream/deepstream-5.1/sources/includes/nvdsmeta_schema.h"
#include "nvdsmeta_schema.h"
namespace py = pybind11;
MyObject *alloc_my_object()
{
return new MyObject();
}
PYBIND11_MODULE(pyds_custom_meta, m)
{
py::enum_<NvDsObjectType>(m, "NvDsObjectType", py::module_local())
.value("OBJECT_TYPE_MY_CUSTOM", NvDsObjectType::NVDS_OBJECT_TYPE_CUSTOM)
.export_values();
py::enum_<NvDsPayloadType>(m, "NvDsPayloadType", py::module_local())
.value("MY_PAYLOAD_1", NvDsPayloadType::NVDS_PAYLOAD_CUSTOM)
.export_values();
py::class_<MyObject>(m, "MyObject", py::module_local())
.def(py::init<>())
.def_readwrite("number", &MyObject::number)
.def_static(
"cast", [](void *data) {
return (MyObject*)data;
},
py::return_value_policy::reference);
m.doc() = "This is a Python binding of C++ Maia Library";
m.def("alloc_my_object", &alloc_my_object, py::return_value_policy::reference);
}
Where instead ot the custom type you use, I switched to the NVDS_OBJECT_TYPE_CUSTOM, since I was not sure how I could have defined it as you do. By following your instructions I was able to generate the bindings and correctly import them in python (deepstream-test-4.py). There, I wanted to use this generated custom object for the custom field “extMsg”, but probably I am making mistakes in doing that and get the error:
incompatible function arguments. The following argument types are supported:
1. (self: pyds.NvDsEventMsgMeta, arg0: capsule) -> None
In the deepstream_test_4.py script I modified the function “generate_event_msg_meta” to use the custom object (similar to the way you proposed in this thread). Specifically:
def generate_event_msg_meta(data):
meta = pyds.NvDsEventMsgMeta.cast(data)
meta.sensorId = 0
meta.placeId = 0
meta.moduleId = 0
meta.sensorStr = "sensor-0"
meta.ts = pyds.alloc_buffer(MAX_TIME_STAMP_LEN + 1)
pyds.generate_ts_rfc3339(meta.ts, MAX_TIME_STAMP_LEN)
print("meta.ts is: " +str(meta.ts))
meta.type = pyds.NvDsEventType.NVDS_EVENT_CUSTOM
meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_CUSTOM
obj = pyds_custom_meta.alloc_my_object()
obj = pyds_custom_meta.MyObject
obj.number = 4
print(obj)
meta.extMsg = obj
meta.extMsgSize = sys.getsizeof(obj)
return obj
As said the code broke when the obj is assigned to the extMsg field of meta. From here, I am a bit lost and am not sure how should I procede.
Do you have some advice?