How to use a non-prescribed message for extMsg in NvDsEventMsgMeta

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU):Jetson
• DeepStream Version : 6.0.1
• JetPack Version (valid for Jetson only): 4.6.1
• TensorRT Version:8.2.1
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs): question
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

I want to use NvDsEventMsgMeta to create a message with my own variables in extMsg.
sample assigns “NvDsVehicleObject” and “NvDsPersonObject” to extMsg as follows.

def generate_event_msg_meta(data, class_id):
    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) #Generate timestamp

    # This demonstrates how to attach custom objects.
    # Any custom object as per requirement can be generated and attached
    # like NvDsVehicleObject / NvDsPersonObject. Then that object should
    # be handled in payload generator library (nvmsgconv.cpp) accordingly.
        meta.type = pyds.NvDsEventType.NVDS_EVENT_MOVING
        meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_VEHICLE
        meta.objClassId = PGIE_CLASS_ID_VEHICLE
        obj = pyds.alloc_nvds_vehicle_object()
        obj = generate_vehicle_meta(obj) #See NvDsVehicleObject example code
        meta.extMsg = obj
        meta.extMsgSize = sys.getsizeof(pyds.NvDsVehicleObject);
    if(class_id == PGIE_CLASS_ID_PERSON):
        meta.type =pyds.NvDsEventType.NVDS_EVENT_ENTRY
        meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_PERSON;
        meta.objClassId = PGIE_CLASS_ID_PERSON
        obj = pyds.alloc_nvds_person_object()
        meta.extMsg = obj
        meta.extMsgSize = sys.getsizeof(pyds.NvDsPersonObject)
    return meta

I would like to assign the following content instead of “NvDsVehicleObject” or “NvDsPersonObject” for example.
Do you have a sample?

class MyData:
        name = 'test' # type :str
        probability = 0.15 # type :float
        name_exists = Ture #type :bool
        #and more …

please refer to this topic.

Thanks for the answer.
However, I am not sure after reading the topic.
Are you saying that I need to change the nvmsgconv library?
Also, I am using python, not c/c++.
I simply want to use python and use the class you presented with extMsg, not the pre-determined “NvDsVehicleObject” etc.
Could you please provide a sample?

yes. from “class MyData:”, it is custom struct. nvmsgconv will convert the struct to Json format. please refer to generate_event_message_minimal, the path isopt\nvidia\deepstream\deepstream\sources\libs\nvmsgconv\deepstream_schema\eventmsg_payload.cpp

NvDsObjectType in nvdsmeta_schema.h support NVDS_OBJECT_TYPE_CUSTOM type. deepstream_python_apps is opensource. you can add a python binding like alloc_nvds_person_object for struct NvDsCustomMsgInfo. then modify nvmsgconv plugin to generate json string.

In deepstream-test4, there is sample to send jpeg file. the app adds a custom buffer “image;image_format;image_widthximage_height;time;encoded_data” to usermeta. you don’t need to modify nvmsgconv. nvmsgconv will convert this buffer to Json string. please refer to readme and code for the more details.

Thank you.
I will refer to it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.