'dsexample' plugin :: how to crop bounding box without scaling or maintaining aspect ratio

I have been testing deepstream_sdk_v4.0_jetson/sources/gst-plugins/gst-dsexample to crop bounding box and save in cv::Mat format. I have slightly modified the gst-dsexample.cpp to save the cv::Mat on local path.

........
........
/* Default values for properties */
#define DEFAULT_UNIQUE_ID 15
#define DEFAULT_PROCESSING_WIDTH 640 //640
#define DEFAULT_PROCESSING_HEIGHT 480 // 480
#define DEFAULT_PROCESS_FULL_FRAME TRUE
#define DEFAULT_GPU_ID 0
.......
.......
static GstFlowReturn
get_converted_mat (GstDsExample * dsexample, NvBufSurface *input_buf, gint idx,
    NvOSD_RectParams * crop_rect_params, gdouble & ratio, gint input_width,
    gint input_height)
{
................
................
 in_mat =
      cv::Mat (dsexample->processing_height, dsexample->processing_width,
      CV_8UC4, dsexample->inter_buf->surfaceList[0].mappedAddr.addr[0],
      dsexample->inter_buf->surfaceList[0].pitch);

  cv::cvtColor (in_mat, *dsexample->cvmat, CV_RGBA2BGR);
  cv::imwrite("/path/to/frame.jpg", in_mat);
.......
.......

And run the command:

$ gst-launch-1.0 filesrc location= <mp4-file> ! qtdemux ! h264parse ! nvv4l2decoder ! m.sink_0 nvstreammux name=m batch-size=1 width=1280 height=720 ! nvinfer config-file-path= <primary-detector-config> ! nvvideoconvert ! dsexample full-frame=0 <other-properties> ! nvdsosd ! nveglglessink

It saves the image in local path, but the image is scaled to 640x480 as defined on the code, resulting in extra black pixels in the image (as shown on the links bellow). I only need the cropped bounding box without caring for scaling or aspect ratio.

Could anyone suggest me how can I do that?

https://ibb.co/rFGZqD5
https://ibb.co/0Zcgr2h

Hi,
Please refer to
https://devtalk.nvidia.com/default/topic/1061422/deepstream-sdk/how-to-crop-the-image-and-save/post/5375174/#5375174