How to encode multiple images using the same objectMeta inside obj_meta_list

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) - GPU
• DeepStream Version - 6.0.1
• Issue Type( questions, new requirements, bugs) - new requirements
• Requirement details

I want to save a detected object and also the whole scene of that detection. I’m using the same objMeta from the frameMeta->obj_meta_list. I noticed my object image also saved in higher resolution with extra padding. Its like I can’t use the same object meta to save two images. Is there a work around for this.

I use the following source code.

    NvDsObjEncUsrArgs userData = {false};
    /* To be set by user */
    userData.saveImg = false;
    userData.attachUsrMeta = true;
    /* Preset */
    userData.objNum = objMeta->object_id;
    /* Quality */
    userData.quality = 95;
    /*Main Function Call */
    nvds_obj_enc_process(objEncContext, &userData, ipSurf, objMeta, frameMeta);

    NvDsObjEncUsrArgs userData1 = {false};
    userData1.saveImg = false;
    userData1.attachUsrMeta = true;
    userData1.scaleImg = true;
    userData1.scaledWidth = 960;
    userData1.scaledHeight = 540;
    userData1.objNum = objMeta->object_id;
    objMeta->rect_params.width = frameMeta->source_frame_width;
    objMeta->rect_params.height = frameMeta->source_frame_height;
    objMeta-> = 0.0f ;
    objMeta->rect_params.left = 0.0f ;
    userData1.quality = 95;
    nvds_obj_enc_process(objEncContext, &userData1, ipSurf, objMeta, frameMeta);

Hi @chinthy2

I would try also changing the object meta rect params before your second encoder call:

    objMeta->rect_params.width = frameMeta->source_frame_width;
    objMeta->rect_params.height = frameMeta->source_frame_height;
    objMeta-> = 0.0f ;
    objMeta->rect_params.left = 0.0f ;

Let me know if this helps

Hi @miguel.taylor , there was an typo in my source code. My code is exaclty same as your suggestion.
What I understand is since I updated the objMeta->rect_params it affected the first nvds_obj_enc_process making the size of that image source_frame_width x source_frame_height with extra black padding.

Seems like the nvds_obj_enc_process takes in objMeta not as copy but as a pointer or reference variable. By the time nvds_obj_enc_process_finishe is called objMeta->rect_params are new values.

nvds_obj_enc_process is used to enqueue an object crop for JPEG encode, if want to dump the whole frame, you can leverage NvBufSurface. please refer to How to convert NvBufSurface to jpeg?

Thanks @fanzh for the NvBufSurface to jpeg reference. I have few questions about this workflow.

  • The reference workflow cudamemcopy the NV12 data from nvbufsurface to the host side and let OpenCV rotate NV12 to RGB and encode to JPEG in CPU. Will it drastically reduce the Pipeline FPS.

  • Is there a way to encode NV12 device data from nvbufsurface using nvJPEG APIs to gain better performance?

nvds_obj_enc_process is a better method because it is simple to use and will do HW acceleration. please refer to the following code:

    nvds_obj_enc_process (ctx, &objData, ip_surf, obj_meta, frame_meta);

      NvDsObjectMeta newMeta;
      NvDsObjEncUsrArgs userData = { 0 };
      /* To be set by user */
      userData.saveImg = save_img;
      /* Set if Image scaling Required */
      userData.scaleImg = FALSE;
      userData.scaledWidth = 0;
      userData.scaledHeight = 0;
      /* Preset */
      userData.objNum = num_rects;
      /* Quality */
      userData.quality = 80;
      newMeta.rect_params.width = frame_meta->source_frame_width;
      newMeta.rect_params.height = frame_meta->source_frame_height; = 0.0f;
      newMeta.rect_params.left = 0.0f;
      static int i = 1;
      char sbuf[32] = {0};
      sprintf(userData.fileNameImg, "%d.jpg", i++);
      /*Main Function Call */
      nvds_obj_enc_process (ctx, &userData, ip_surf, &newMeta, frame_meta);

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