OpenCV Mat to NvBufSurface (to use in NvBufSurfTransform)

Hi,
Please check the code in

deepstream_sdk_v4.0.2_jetson\sources\gst-plugins\gst-dsexample\gstdsexample.cpp

The working solution is to create RGBA buffer through NvBufSurfaceCreate(), and map it to cv::Mat

  // Map the buffer so that it can be accessed by CPU
  if (NvBufSurfaceMap (dsexample->inter_buf, 0, 0, NVBUF_MAP_READ) != 0){
    goto error;
  }

  // Cache the mapped data for CPU access
  NvBufSurfaceSyncForCpu (dsexample->inter_buf, 0, 0);

  // Use openCV to remove padding and convert RGBA to BGR. Can be skipped if
  // algorithm can handle padded RGBA data.
  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);

After the processing is done, call NvBufSurfaceSyncForDevice() and unmap the surface.