How do I get a picture with a rectangular frame?

I need to get a picture with a rectangular box, and now I get the picture from frame_meta, but there is no rectangular box. I don’t know why, I hope you can help me.
This is my code:

for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
    l_frame = l_frame->next) {
      NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
      gint frame_width = (gint)nvsurface->surfaceList[frame_meta->batch_id].width;
      gint frame_height = (gint)nvsurface->surfaceList[frame_meta->batch_id].height;
      void *frame_data = nvsurface->surfaceList[frame_meta->batch_id].mappedAddr.addr[0];
      size_t frame_step = nvsurface->surfaceList[frame_meta->batch_id].pitch;
      in_mat = cv::Mat(frame_height,frame_width,CV_8UC4,frame_data,frame_step);
      out_mat = cv::Mat(frame_height,frame_width,CV_8UC3);
      cv::cvtColor(in_mat,out_mat,CV_RGBA2BGR);

HI
you want to draw detected objects, is this what you mean, if yes, the info you need is in NvDsObjectMeta,
refer to this, https://docs.nvidia.com/metropolis/deepstream/plugin-manual/index.html#page/DeepStream_Plugin_Manual%2Fdeepstream_plugin_metadata.03.2.html%23wwconnect_header,
you need to iterate through object meta list within frame, fill struct GstNvOsd,
and draw it over frame buffer,
refer to: int nvll_osd_draw_rectangles(void *nvosd_ctx, NvOSD_FrameRectParams *frame_rect_params);
which from sources/includes/nvll_osd_api.h

Thanks amycao, I will try this.

Hello,amycao.
The picture I am getting now is obtained from frame_meta using NvBufSurface.
I found int nvll_osd_draw_rectangles (void * nvosd_ctx, NvOSD_FrameRectParams * frame_rect_params) based on your reply, but I do n’t know how to use it, can you provide me a copy Its code? If I could, I would be grateful.
Best wishes to you!

oh, this API supposed to draw buffer blended from original buffer and NvOSD_FrameRectParams on the screen, but you want to save this blended buffer to one local file, Does using sink type 3 File meet your requirements?