• Hardware Platform:GPU
• DeepStream Version:6.3.0
• TensorRT Version:8.6.1.6
• NVIDIA GPU Driver Version:535.86.05
• Issue Type:questions
Hi,
I would like to send jpeg with rectangle to msgbroker.
Refer to /opt/nvidia/deepstream/deepstream-6.3/sources/gst-plugins/gst-nvdsosd/gstnvdsosd.c
, I made some change based on deepstream_test5_app
like that:
static void
bbox_generated_probe_after_analytics (AppCtx * ctx, GstBuffer * buf,
NvDsBatchMeta * batch_meta, guint index)
{
AppCtx5 *ctx5 = (AppCtx5 *)ctx;
GstMapInfo inmap = GST_MAP_INFO_INIT;
if (!gst_buffer_map (buf, &inmap, GST_MAP_READ)) {
GST_ERROR ("input buffer mapinfo failed");
return;
}
NvBufSurface *ip_surf = (NvBufSurface *) inmap.data;
gst_buffer_unmap (buf, &inmap);
NvDsObjectMeta *obj_meta = NULL;
GstClockTime buffer_pts;
guint32 stream_id;
NvBufSurface surface;
NvOSD_FrameRectParams frame_rect_params;
int rect_cnt = 0, obj_cnt = 0;
for (NvDsMetaList * l_frame = batch_meta->frame_meta_list; l_frame != NULL;
l_frame = l_frame->next) {
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) l_frame->data;
stream_id = frame_meta->source_id;
GstClockTime buf_ntp_time = 0;
if (playback_utc == FALSE) {
/** Calculate the buffer-NTP-time
* derived from this stream's RTCP Sender Report here:
*/
StreamSourceInfo *src_stream = &testAppCtx->streams[stream_id];
buf_ntp_time = frame_meta->ntp_timestamp;
if (buf_ntp_time < src_stream->last_ntp_time) {
NVGSTDS_WARN_MSG_V ("Source %d: NTP timestamps are backward in time."
" Current: %lu previous: %lu", stream_id, buf_ntp_time,
src_stream->last_ntp_time);
}
src_stream->last_ntp_time = buf_ntp_time;
}
surface = *ip_surf;
surface.surfaceList = &(ip_surf->surfaceList[frame_meta->batch_id]);
surface.numFilled = surface.batchSize = 1;
for (GList *l = frame_meta->obj_meta_list; l != NULL; l = l->next) {
/* Now using above information we need to form a text that should
* be displayed on top of the bounding box, so lets form it here. */
obj_meta = (NvDsObjectMeta *) (l->data);
ctx5->rect_params[rect_cnt++] = obj_meta->rect_params;
obj_cnt++;
if (rect_cnt == MAX_OSD_ELEMS) {
frame_rect_params.num_rects = rect_cnt;
frame_rect_params.rect_params_list = ctx5->rect_params;
/** Use of buf_ptr is deprecated, use 'frame_rect_params.surf' instead */
frame_rect_params.buf_ptr = NULL;
frame_rect_params.mode = MODE_GPU;
frame_rect_params.surf = &surface;
nvll_osd_draw_rectangles (ctx5->nvdsosd_context, &frame_rect_params);
rect_cnt = 0;
}
{
/**
* Enable only if this callback is after tiler
* NOTE: Scaling back code-commented
* now that bbox_generated_probe_after_analytics() is post analytics
* (say pgie, tracker or sgie)
* and before tiler, no plugin shall scale metadata and will be
* corresponding to the nvstreammux resolution
*/
float scaleW = 0;
float scaleH = 0;
/* Frequency of messages to be send will be based on use case.
* Here message is being sent for first object every 30 frames.
*/
buffer_pts = frame_meta->buf_pts;
if (!ctx5->base.config.streammux_config.pipeline_width
|| !ctx5->base.config.streammux_config.pipeline_height) {
g_print ("invalid pipeline params\n");
return;
}
LOGD ("stream %d==%d [%d X %d]\n", frame_meta->source_id,
frame_meta->pad_index, frame_meta->source_frame_width,
frame_meta->source_frame_height)
scaleW = (float) frame_meta->source_frame_width / (float) ctx5->base.config.streammux_config.pipeline_width;
scaleH = (float) frame_meta->source_frame_height / (float) ctx5->base.config.streammux_config.pipeline_height;
if (playback_utc == FALSE) {
/** Use the buffer-NTP-time derived from this stream's RTCP Sender
* Report here:
*/
buffer_pts = buf_ntp_time;
}
/** Generate NvDsEventMsgMeta for every object */
NvDsEventMsgMeta *msg_meta =
(NvDsEventMsgMeta *) g_malloc0 (sizeof (NvDsEventMsgMeta));
generate_event_msg_meta (ctx5, msg_meta, obj_meta->class_id, TRUE,
/**< useTs NOTE: Pass FALSE for files without base-timestamp in URI */
buffer_pts,
ctx5->base.config.multi_source_config[stream_id].uri, (int)stream_id,
ctx5->base.config.multi_source_config[stream_id].camera_id,
obj_meta, scaleW, scaleH, frame_meta);
testAppCtx->streams[stream_id].meta_number++;
NvDsUserMeta *user_event_meta =
nvds_acquire_user_meta_from_pool (batch_meta);
if (user_event_meta) {
/*
* Since generated event metadata has custom objects for
* Vehicle / Person which are allocated dynamically, we are
* setting copy and free function to handle those fields when
* metadata copy happens between two components.
*/
user_event_meta->user_meta_data = (void *) msg_meta;
user_event_meta->base_meta.batch_meta = batch_meta;
user_event_meta->base_meta.meta_type = NVDS_EVENT_MSG_META;
user_event_meta->base_meta.copy_func =
(NvDsMetaCopyFunc) meta_copy_func;
user_event_meta->base_meta.release_func =
(NvDsMetaReleaseFunc) meta_free_func;
nvds_add_user_meta_to_frame (frame_meta, user_event_meta);
} else {
g_print ("Error in attaching event meta to buffer\n");
}
}
}
frame_rect_params.num_rects = rect_cnt;
frame_rect_params.rect_params_list = ctx5->rect_params;
/** Use of buf_ptr is deprecated, use 'frame_rect_params.surf' instead */
frame_rect_params.buf_ptr = NULL;
frame_rect_params.mode = MODE_GPU;
frame_rect_params.surf = &surface;
int ret = nvll_osd_draw_rectangles (ctx5->nvdsosd_context, &frame_rect_params);
if (0 != obj_cnt) {
NvDsObjEncUsrArgs frameData = { 0 };
/* Preset */
frameData.isFrame = 1;
/* To be set by user */
frameData.saveImg = TRUE;
frameData.attachUsrMeta = TRUE;
/* Set if Image scaling Required */
frameData.scaleImg = FALSE;
frameData.scaledWidth = 0;
frameData.scaledHeight = 0;
/* Quality */
frameData.quality = 80;
/* Main Function Call */
nvds_obj_enc_process (ctx5->obj_ctx_handle, &frameData, ip_surf, NULL, frame_meta);
}
testAppCtx->streams[stream_id].frameCount++;
}
nvds_obj_enc_finish (ctx5->obj_ctx_handle);
}
the nvdsosd_context
has been init using nvll_osd_create_context ()
. I can get image from msgbroker, but there is no rectangle on the image. Is there something wrong with my code?