# Adding analytics to Custom schema payload

**URL:** <https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396>\
**Category:** DeepStream SDK\
**Created:** [September 23, 2023, 3:43pm UTC](https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396 "2023-09-23T15:43:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.sowmiya86](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@d.sowmiya86](https://forums.developer.nvidia.com/u/d.sowmiya86)\
**Post date:** [September 23, 2023, 3:43pm UTC](https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396/1 "2023-09-23T15:43:36Z")

</div>

Please provide the following information when requesting support.

•We have our custom trained model, where there was a requirement to calculate the entry /exit count . We have added this functionality to deep stream test 5 application by integrating it with deepstream-occupancy-analytics ([GitHub - NVIDIA-AI-IOT/deepstream-occupancy-analytics: This is a sample application for counting people entering/leaving in a building using NVIDIA Deepstream SDK, Transfer Learning Toolkit (TLT), and pre-trained models. This application can be used to build real-time occupancy analytics applications for smart buildings, hospitals, retail, etc. The application is based on deepstream-test5 sample application.](https://github.com/NVIDIA-AI-IOT/deepstream-occupancy-analytics)). however we are not able to receive the analytics data via (257) PAYLOAD\_CUSTOM - Custom schema payload or (1)PAYLOAD\_DEEPSTREAM\_MINIMAL - Deepstream schema payload minimal. kindly need your guidance to resolve this issue .  
Please let us know the feasibility to add the analytics feature to generate\_dsmeta\_message\_minimal in dsmeta\_payload.cpp file

gchar\* generate\_dsmeta\_message\_minimal (void \*privData, void _frameMeta)  
{  
/_  
The JSON structure of the frame  
{  
“version”: “4.0”,  
“id”: “frame-id”,  
“@timestamp”: “2018-04-11T04:59:59.828Z”,  
“sensor”: “sensor-id”,  
“objects”: [  
“…object-1 attributes…”,  
“…object-2 attributes…”,  
“…object-3 attributes…”  
]  
}  
\*/

/\*  
An example object with Vehicle object-type  
{  
“version”: “4.0”,  
“id”: “frame-id”,  
“@timestamp”: “2018-04-11T04:59:59.828Z”,  
“sensorId”: “sensor-id”,  
“objects”: [  
“957|1834|150|1918|215|Vehicle|#|sedan|Bugatti|M|blue|CA 444|California|0.8”,  
“…”  
]  
}  
\*/

JsonNode \*rootNode;  
JsonObject \*jobject;  
JsonArray \*jArray;  
stringstream ss;  
gchar \*message = NULL;

jArray = json\_array\_new ();

NvDsFrameMeta \*frame\_meta = (NvDsFrameMeta \*) frameMeta;  
for (NvDsObjectMetaList \*obj\_l = frame\_meta-\>obj\_meta\_list; obj\_l; obj\_l = obj\_l-\>next) {  
NvDsObjectMeta \*obj\_meta = (NvDsObjectMeta \*) obj\_l-\>data;  
if (obj\_meta == NULL) {  
// Ignore Null object.  
continue;  
}

```
// bbox sub object
float scaleW = (float) frame_meta->source_frame_width /
                    (frame_meta->pipeline_width == 0) ? 1:frame_meta->pipeline_width;
float scaleH = (float) frame_meta->source_frame_height /
                    (frame_meta->pipeline_height == 0) ? 1:frame_meta->pipeline_height;

float left = obj_meta->rect_params.left * scaleW;
float top = obj_meta->rect_params.top * scaleH;
float width = obj_meta->rect_params.width * scaleW;
float height = obj_meta->rect_params.height * scaleH;

ss.str("");
ss.clear();
ss << obj_meta->object_id << "|" << left << "|" << top
   << "|" << left + width << "|" << top + height
   << "|" << obj_meta->obj_label;

if(g_list_length(obj_meta->classifier_meta_list) > 0) {
    ss << "|#";
    //Add classifiers for the object, if any
    for(NvDsClassifierMetaList *cl = obj_meta->classifier_meta_list; cl ; cl=cl->next) {
      NvDsClassifierMeta *cl_meta = (NvDsClassifierMeta*) cl->data;
      for(NvDsLabelInfoList *ll = cl_meta->label_info_list; ll ; ll=ll->next) {
        NvDsLabelInfo *ll_meta = (NvDsLabelInfo*) ll->data;
        ss<< "|" << ll_meta->result_label;
      }
    }
    ss << "|" << obj_meta->confidence;
}
json_array_add_string_element (jArray, ss.str().c_str());

```

}

//generate timestamp  
char ts[MAX\_TIME\_STAMP\_LEN + 1];  
generate\_ts\_rfc3339 (ts, MAX\_TIME\_STAMP\_LEN);

//fetch sensor id  
string sensorId=“0”;  
NvDsPayloadPriv \*privObj = (NvDsPayloadPriv \*) privData;  
auto idMap = privObj-\>sensorObj.find (frame\_meta-\>source\_id);  
if (idMap != privObj-\>sensorObj.end()) {  
NvDsSensorObject &obj = privObj-\>sensorObj[frame\_meta-\>source\_id];  
sensorId = obj.id;  
}

jobject = json\_object\_new ();  
json\_object\_set\_string\_member (jobject, “version”, “4.0”);  
json\_object\_set\_string\_member (jobject, “id”, to\_string(frame\_meta-\>frame\_num).c\_str());  
json\_object\_set\_string\_member (jobject, “@timestamp”, ts);  
json\_object\_set\_string\_member (jobject, “sensorId”, sensorId.c\_str());

json\_object\_set\_array\_member (jobject, “objects”, jArray);

JsonArray \*custMsgjArray = json\_array\_new ();  
//Search for any custom message blob within frame usermeta list  
for (NvDsUserMetaList \*l = frame\_meta-\>frame\_user\_meta\_list; l; l = l-\>next) {  
NvDsUserMeta \*frame\_usermeta = (NvDsUserMeta \*) l-\>data;  
if(frame\_usermeta && frame\_usermeta-\>base\_meta.meta\_type == NVDS\_CUSTOM\_MSG\_BLOB) {  
NvDsCustomMsgInfo \*custom\_blob = (NvDsCustomMsgInfo \*) frame\_usermeta-\>user\_meta\_data;  
string msg = string((const char \*) custom\_blob-\>message, custom\_blob-\>size);  
json\_array\_add\_string\_element (custMsgjArray, msg.c\_str());  
}  
}  
if(json\_array\_get\_length(custMsgjArray) \> 0)  
json\_object\_set\_array\_member (jobject, “customMessage”, custMsgjArray);  
else  
json\_array\_unref(custMsgjArray);

rootNode = json\_node\_new (JSON\_NODE\_OBJECT);  
json\_node\_set\_object (rootNode, jobject);

message = json\_to\_string (rootNode, TRUE);  
json\_node\_free (rootNode);  
json\_object\_unref (jobject);

return message;  
}

---

<div class="post-metadata">

**Author:** ![Morganh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/morganh/32/9748_2.png) [@Morganh](https://forums.developer.nvidia.com/u/Morganh)\
**Post date:** [September 24, 2023, 1:32pm UTC](https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396/2 "2023-09-24T13:32:38Z")

</div>

Hi,  
Seems that is it is a topic of deepstream. Changing it to Deepstream forum.

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [September 25, 2023, 1:30am UTC](https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396/4 "2023-09-25T01:30:27Z")

</div>

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)

• DeepStream Version

• JetPack Version (valid for Jetson only)

• TensorRT Version

• NVIDIA GPU Driver Version (valid for GPU only)

• Issue Type( questions, new requirements, bugs)

• 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)

---

<div class="post-metadata">

**Author:** ![fanzh](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/fanzh/32/115955_2.png) [@fanzh](https://forums.developer.nvidia.com/u/fanzh)\
**Post date:** [October 8, 2023, 8:17am UTC](https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396/5 "2023-10-08T08:17:13Z")

</div>

**There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks**

please refer to this [topic](https://forums.developer.nvidia.com/t/how-to-add-custom-data-to-analytics-or-send-data-via-kafka-inside-deep-stream/247944).

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [October 24, 2023, 2:57am UTC](https://forums.developer.nvidia.com/t/adding-analytics-to-custom-schema-payload/267396/6 "2023-10-24T02:57:40Z")

</div>

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