I am working on customizing “deepstream-3d-action-recognition”
I want to convert an image of a frame with motion recognition (for example, a frame recognized as “walk”) to base64 and send it as metadata.
Therefore, in the “pgie_src_pad_buffer_probe()” function of “deepstream_3d_action_recognition.cpp”, I want to use the code below to obtain “NvBufSurface” data and convert it to jpeg.
In “deepstream-3d-action-recognition”, there is no object data because it recognizes an action, not an object.
The topic you recommended is using the “nvds_obj_enc_process” function. Can I use that function without object data?
What I want is frame image
Can you share the purpose of metadata ?
If you just want convert frame image to jpeg after pgie,add tee plugin to your app. such as pgie --> tee --> nvjpegenc --> filesink
As you said, if you configure the pipeline with “pgie → tee → nvjpegenc”, can the jpeg image converted from “nvjpegenc” be converted to base64 and transmitted?
Is there any sample app that converts frame to image with that structure(pgie → tee → nvjpegenc)?
I don’t have enough skills, so I need a code that I can refer to
Refer to the sample implementation in /opt/nvidia/deepstream/deepstream/sources/apps/sample_apps/deepstream-image-meta-test/deepstream_image_meta_test.c
I’ve modified the functionality to do base64 encoding. I think you can call your json builder with the base64Data.
#include <iostream>
#include <string>
#include <boost/algorithm/base64.hpp>
static GstPadProbeReturn
pgie_src_pad_buffer_probe(GstPad *pad, GstPadProbeInfo *info, gpointer ctx)
{
GstBuffer *buf = (GstBuffer *)info->data;
GstMapInfo inmap = GST_MAP_INFO_INIT;
if (!gst_buffer_map(buf, &inmap, GST_MAP_READ))
{
GST_ERROR("input buffer mapinfo failed");
return GST_FLOW_ERROR;
}
NvBufSurface *ip_surf = (NvBufSurface *)inmap.data;
gst_buffer_unmap(buf, &inmap);
NvDsObjectMeta *obj_meta = NULL;
guint vehicle_count = 0;
guint person_count = 0;
NvDsMetaList *l_frame = NULL;
NvDsMetaList *l_obj = NULL;
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
// iterate through all the frames and objects to do encoding
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next)
{
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
guint num_rects = 0;
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
obj_meta = (NvDsObjectMeta *)(l_obj->data);
/* Conditions that user needs to set to encode the detected objects of interest */
if ((obj_meta->class_id == PGIE_CLASS_ID_PERSON || obj_meta->class_id == PGIE_CLASS_ID_VEHICLE))
{
NvDsObjEncUsrArgs userData = {0};
/* To be set by user */
userData.saveImg = true;
userData.attachUsrMeta = true;
/* Set if Image scaling Required */
userData.scaleImg = false;
userData.scaledWidth = 0;
userData.scaledHeight = 0;
/* Preset */
userData.objNum = num_rects;
/* Quality */
userData.quality = 80;
/* attach the userData to obj_meta with encoded objects */
nvds_obj_enc_process(ctx, &userData, ip_surf, obj_meta, frame_meta);
}
}
}
nvds_obj_enc_finish(ctx); // wait until all the selected objects to be encoded
// iterate through all the frames and get the encoded usermetadata
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL; l_frame = l_frame->next)
{
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
guint num_rects = 0;
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
obj_meta = (NvDsObjectMeta *)(l_obj->data);
NvDsUserMetaList *usrMetaList = obj_meta->obj_user_meta_list;
while (usrMetaList != NULL)
{
NvDsUserMeta *usrMetaData = (NvDsUserMeta *)usrMetaList->data;
if (usrMetaData->base_meta.meta_type == NVDS_CROP_IMAGE_META)
{
// encode the jpeg binary buffer to base64
NvDsObjEncOutParams *enc_jpeg_image = (NvDsObjEncOutParams *)usrMetaData->user_meta_data;
uint8_t *buffer = enc_jpeg_image->outBuffer;
size_t bufferLength = enc_jpeg_image->outLen;
std::string binaryData(reinterpret_cast<const char*>(buffer), bufferLength);
std::string base64Data = boost::algorithm::base64_encode(binaryData);
}
else
{
usrMetaList = usrMetaList->next;
}
}
}
}
return GST_PAD_PROBE_OK;
}