def generate_event_msg_meta(data, class_id): meta = pyds.glist_get_nvds_event_msg_meta(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) # 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. if (class_id == PGIE_CLASS_ID_VEHICLE): 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) 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() obj = generate_person_meta(obj) meta.extMsg = obj meta.extMsgSize = sys.getsizeof(pyds.NvDsPersonObject) return meta
def generate_event_msg_meta(data, class_id, timestamp): logging.debug("generate_event_msg_meta: BEGIN") meta = pyds.NvDsEventMsgMeta.cast(data) meta.sensorId = 0 meta.placeId = 0 meta.moduleId = 0 meta.sensorStr = "sensor-0" meta.ts = create_pyds_string(str(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. if class_id == PGIE_CLASS_ID_VEHICLE: 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) meta.extMsg = obj meta.extMsgSize = sys.getsizeof(pyds.NvDsVehicleObject) elif 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() obj = generate_person_meta(obj) meta.extMsg = obj meta.extMsgSize = sys.getsizeof(pyds.NvDsPersonObject) logging.debug("generate_event_msg_meta: END") return meta
def meta_copy_func(data, user_data): logging.debug("meta_copy_func: BEGIN") # Cast data to pyds.NvDsUserMeta user_meta = pyds.NvDsUserMeta.cast(data) src_meta_data = user_meta.user_meta_data # Cast src_meta_data to pyds.NvDsEventMsgMeta srcmeta = pyds.NvDsEventMsgMeta.cast(src_meta_data) # Duplicate the memory contents of srcmeta to dstmeta # First use pyds.get_ptr() to get the C address of srcmeta, then # use pyds.memdup() to allocate dstmeta and copy srcmeta into it. # pyds.memdup returns C address of the allocated duplicate. dstmeta_ptr = pyds.memdup(pyds.get_ptr(srcmeta), sys.getsizeof(pyds.NvDsEventMsgMeta)) # Cast the duplicated memory to pyds.NvDsEventMsgMeta dstmeta = pyds.NvDsEventMsgMeta.cast(dstmeta_ptr) # Duplicate contents of ts field. Note that reading srcmeta.ts # returns its C address. This allows to memory operations to be # performed on it. dstmeta.ts = pyds.strdup(srcmeta.ts) # Copy the sensorStr. This field is a string property. # The getter (read) returns its C address. The setter (write) # takes string as input, allocates a string buffer and copies # the input string into it. # pyds.get_string() takes C address of a string and returns # the reference to a string object and the assignment inside the binder copies content. dstmeta.sensorStr = pyds.get_string(srcmeta.sensorStr) if srcmeta.objSignature.size > 0: dstmeta.objSignature.signature = pyds.memdup( srcmeta.objSignature.signature, srcMeta.objSignature.size) dstmeta.objSignature.size = srcmeta.objSignature.size if srcmeta.extMsgSize > 0: if srcmeta.objType == pyds.NvDsObjectType.NVDS_OBJECT_TYPE_VEHICLE: srcobj = pyds.NvDsVehicleObject.cast(srcmeta.extMsg) obj = pyds.alloc_nvds_vehicle_object() obj.type = pyds.get_string(srcobj.type) obj.make = pyds.get_string(srcobj.make) obj.model = pyds.get_string(srcobj.model) obj.color = pyds.get_string(srcobj.color) obj.license = pyds.get_string(srcobj.license) obj.region = pyds.get_string(srcobj.region) dstmeta.extMsg = obj dstmeta.extMsgSize = sys.getsizeof(pyds.NvDsVehicleObject) elif srcmeta.objType == pyds.NvDsObjectType.NVDS_OBJECT_TYPE_PERSON: srcobj = pyds.NvDsPersonObject.cast(srcmeta.extMsg) obj = pyds.alloc_nvds_person_object() obj.age = srcobj.age obj.gender = pyds.get_string(srcobj.gender) obj.cap = pyds.get_string(srcobj.cap) obj.hair = pyds.get_string(srcobj.hair) obj.apparel = pyds.get_string(srcobj.apparel) dstmeta.extMsg = obj dstmeta.extMsgSize = sys.getsizeof(pyds.NvDsVehicleObject) logging.debug("meta_copy_func: END") return dstmeta
def generate_event_msg_meta(data, class_id, pravega_timestamp): logging.info("generate_event_msg_meta: BEGIN") meta = pyds.NvDsEventMsgMeta.cast(data) meta.sensorId = 0 meta.placeId = 0 meta.moduleId = 0 meta.sensorStr = "sensor-0" # We store the TAI timestamp in videoPath because there isn't a better place that is output by nvmsgconv. meta.videoPath = str(pravega_timestamp.nanoseconds()) # Also store UTC timestamp as a string like "2021-01-02T22:57:10.490000+00:00". meta.ts = create_pyds_string(pravega_timestamp.to_iso_8601()) # 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. if class_id == PGIE_CLASS_ID_VEHICLE: 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) meta.extMsg = obj meta.extMsgSize = sys.getsizeof(pyds.NvDsVehicleObject) elif 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() obj = generate_person_meta(obj) meta.extMsg = obj meta.extMsgSize = sys.getsizeof(pyds.NvDsPersonObject) elif class_id == PGIE_CLASS_ID_NONE: meta.type = pyds.NvDsEventType.NVDS_EVENT_EMPTY meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_UNKNOWN logging.debug("generate_event_msg_meta: END") return meta