Map cv::Mat to NvBuffer

I am mapping an NvBuffer to an opencv as follows:

  Mat input_frame;

  NvBufferMemMap(input_dmabufs_.back(), 0, NvBufferMem_Read, &pdata);

  NvBufferMemSyncForCpu(input_dmabufs_.back(), 0, &pdata);
  cv::Mat imgbuf = cv::Mat(input_frame_height_,
                            input_frame_width_,
                            CV_8UC4, pdata);
  
  cvtColor(imgbuf, imgbuf, cv::COLOR_RGBA2BGR);
  NvBufferMemUnMap(input_dmabufs_.back(), 0, &pdata);

I then do some processing on the frame with opencv.

Now I would like to transform the processed opencv image back to a NvBuffer. How can this be done?

Hi,
Since NvBuffer supports RGBA and does not support BGR, one possible solution is to create another RGBA NVBuffer and map it to another cv::Mat. And then convert the BGR back to RGBA. It has one more conversion on CPU so if the function works, there may be concern in performance.