How to draw line on the frame?

Hi,
jetson-nano
deepstream4.0

1.ssd inference in deepstream
2.draw line use gst-plugins.
3.show the bbox(from the ssd)and the line on the frame

At step 2
gst-dsexample add “obj_lable” to the frame.
I Want to add the line to frame.
The line is the result of the opencv.
How to draw line on the frame?

Hi
You can refer to sources/apps/sample_apps/deepstream-infer-tensor-meta-test/deepstream_infer_tensor_meta_test.cpp::osd_sink_pad_buffer_probe

it shows how to add labels, and below code show how to add lines,

/* Text background color */
txt_params->set_bg_clr = 1;
txt_params->text_bg_clr.red = 0.0;
txt_params->text_bg_clr.green = 0.0;
txt_params->text_bg_clr.blue = 0.0;
txt_params->text_bg_clr.alpha = 1.0;

add below code after above code

NvOSD_LineParams *line_params  = display_meta->line_params;
display_meta->num_lines = 2;
line_params[0].x1 = 30;
line_params[0].y1 = 50;
line_params[0].x2 = 150;
line_params[0].y2 = 150;
line_params[1].x1 = 50;
line_params[1].y1 =  110;
line_params[1].x2 = 150;
line_params[1].y2 = 150;
line_params[0].line_width = 2;
line_params[0].line_color = (NvOSD_ColorParams){1.0, 0.0, 0.0, 0.5};
line_params[1].line_width = 2;
line_params[1].line_color = (NvOSD_ColorParams){1.0, 0.0, 0.0, 0.5};

OK,Thanks.
I will try.

deepstream4.02
jetson-nano
run deepstream-app -c deepstream_app_config_ssd.txt
(maybe can run other samples)
At deepstream_sdk_v4.0.2_jetson\sources\objectDetector_SSD

Hi,I can draw line on the frame.But the line will be flicker?
I use gst-dsexample of the gst-plugins.

[ds-example]
enable=1
processing-width=640
processing-height=480
full-frame=1
unique-id=15
gpu-id=0

add this to the deepstream_app_config_ssd.txt

and the code if gstdsexample.cpp in the ds-example.

static void
attach_metadata_full_frame (GstDsExample * dsexample, NvDsFrameMeta *frame_meta,
gdouble scale_ratio, DsExampleOutput * output, guint batch_id)
{
NvDsBatchMeta *batch_meta = frame_meta->base_meta.batch_meta;
NvDsDisplayMeta *display_meta = NULL;

static gchar font_name[] = "Serif";

GST_DEBUG_OBJECT (dsexample, "Attaching metadata %d\n", output->numObjects);

display_meta = nvds_acquire_display_meta_from_pool (batch_meta);

NvOSD_LineParams *line_params = display_meta->line_params;
display_meta->num_lines = 2;
line_params[0].x1 = 30;
line_params[0].y1 = 50;
line_params[0].x2 = 150;
line_params[0].y2 = 150;
line_params[1].x1 = 300;
line_params[1].y1 = 300;
line_params[1].x2 = 600;
line_params[1].y2 = 600;
line_params[0].line_width = 20;
line_params[0].line_color = (NvOSD_ColorParams){1.0, 0.0, 0.0, 0.5};
line_params[1].line_width = 20;
line_params[1].line_color = (NvOSD_ColorParams){1.0, 0.0, 0.0, 0.5};
nvds_add_display_meta_to_frame (frame_meta, display_meta);

}

But the line will be flicker? Can you help me?
c8cb8bda7245c87e5c4dccb12b56813.jpg

https://devtalk.nvidia.com/default/topic/1063752/deepstream-sdk/i-want-to-know-how-to-use-roi-top-offset-roi-bottom-offset/

The same issue with me.

Maybe it is a bug of the deepstream4.0??

thanks

Will check, and get back to you.

Hi,
Sorry for a late reply
I do not have this flicker issue, I attached the whole function code, did you have other changes? btw, i am using deepstream-app, config source4***, model is the default within package
static void
attach_metadata_full_frame (GstDsExample * dsexample, NvDsFrameMeta *frame_meta,
gdouble scale_ratio, DsExampleOutput * output, guint batch_id)
{
NvDsBatchMeta *batch_meta = frame_meta->base_meta.batch_meta;
NvDsObjectMeta *object_meta = NULL;
NvDsDisplayMeta *display_meta = NULL;
static gchar font_name = “Serif”;
GST_DEBUG_OBJECT (dsexample, “Attaching metadata %d\n”, output->numObjects);

display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
NvOSD_LineParams *line_params = display_meta->line_params;
display_meta->num_lines = 2;
line_params[0].x1 = 30;
line_params[0].y1 = 50;
line_params[0].x2 = 150;
line_params[0].y2 = 150;
line_params[1].x1 = 50;
line_params[1].y1 = 110;
line_params[1].x2 = 150;
line_params[1].y2 = 150;
line_params[0].line_width = 2;
line_params[0].line_color = (NvOSD_ColorParams){1.0, 0.0, 0.0, 0.5};
line_params[1].line_width = 2;
line_params[1].line_color = (NvOSD_ColorParams){1.0, 0.0, 0.0, 0.5};
nvds_add_display_meta_to_frame (frame_meta, display_meta);

for (gint i = 0; i < output->numObjects; i++) {
DsExampleObject *obj = &output->object[i];
object_meta = nvds_acquire_obj_meta_from_pool(batch_meta);
NvOSD_RectParams & rect_params = object_meta->rect_params;
NvOSD_TextParams & text_params = object_meta->text_params;
// Assign bounding box coordinates
rect_params.left = obj->left;
rect_params.top = obj->top;
rect_params.width = obj->width;
rect_params.height = obj->height;
// Semi-transparent yellow background
rect_params.has_bg_color = 0;
rect_params.bg_color = (NvOSD_ColorParams) {
1, 1, 0, 0.4};
// Red border of width 6
rect_params.border_width = 3;
rect_params.border_color = (NvOSD_ColorParams) {
1, 0, 0, 1};
// Scale the bounding boxes proportionally based on how the
//object/frame was
// scaled during input
rect_params.left /= scale_ratio;
rect_params.top /= scale_ratio;
rect_params.width /= scale_ratio;
rect_params.height /= scale_ratio;
GST_DEBUG_OBJECT (dsexample, “Attaching rect%d of batch%u”
" left->%u top->%u width->%u"
" height->%u label->%s\n", i, batch_id, rect_params.left,
rect_params.top, rect_params.width, rect_params.height, obj->label);
object_meta->object_id = UNTRACKED_OBJECT_ID;
g_strlcpy (object_meta->obj_label, obj->label, MAX_LABEL_SIZE);
// display_text required heap allocated memory
text_params.display_text = g_strdup (obj->label);
// Display text above the left top corner of the object
text_params.x_offset = rect_params.left;
text_params.y_offset = rect_params.top - 10;
// Set black background for the text
text_params.set_bg_clr = 1;
text_params.text_bg_clr = (NvOSD_ColorParams) {
0, 0, 0, 1};
// Font face, size and color
text_params.font_params.font_name = font_name;
text_params.font_params.font_size = 11;
text_params.font_params.font_color = (NvOSD_ColorParams) {
1, 1, 1, 1};
nvds_add_obj_meta_to_frame(frame_meta, object_meta, NULL);
}
}

OK,thank you very much. If the frame rate less than 30,the line maybe flicker.

I has same issue on ‘deepstream_test3_app’ with deepstream 4.
confugure is use 4 rtsp stream and use ‘drop frame interval’ optional, frame rate is 2 frames/second.
I test with nvinfer pipe on ‘sink’ and ‘src’ both is same problem.
The problem is apply on ‘lines’ only, ‘rects’ and ‘labels’ are no problem.

Hi choom,

Please help to open a new topic for your issue. Thanks

OK it seem to other people start new thread. Thank

https://forums.developer.nvidia.com/t/deepstream-draw-line-issues/119006