NvMediaImage to OpenCV Mat

Hi,
I am trying to feed the output frames from the camera to opencv. Can you please tell me how I can convert NvMediaImage to OpenCV Mat?
Thanks

Dear raghavhrishi,
All the data structures in Nvmedia are of abstract type. NvMediaImage does not directly expose the pointer to the image data. You can use NvMediaImageGetBits function to to copy the image content to a buffer. Please refer to https://docs.nvidia.com/drive/nvvib_docs/NVIDIA%20DRIVE%20Linux%20SDK%20Development%20Guide/baggage/group__image__get__put__bits.html#ga08105b012a23b61530fe747a367682e6

hi,
can we convert dwImageCUDA to opencv Mat?thanks!

Dear peng2,
DwImageCUDA can store data in pitch linear(dptr) format and block linear format(cudaArray). Can you please check if data is present in dptr or cudaArray. Please use corresponding CUDA mempcpy function to copy data to buffer. A list of CUDA memcpy functions are provided at CUDA Runtime API :: CUDA Toolkit Documentation.

Is there any NvMediaImage sample?thanks!

Dear Peng2,
You can refer to img_cap sample(save.c file) to know the usage of NvMediaImageGetBits API.

Dear SivaRamaKrishna
where is the save.c?thanks very much!

Dear Peng2,
Please find NVMedia samples at <DriveInstall_PATH>/5050aL_SDK/DriveSDK/drive-t186ref-linux/samples/nvmedia on Host machine.

ok,thanks a lot!

Hello,
Can the NvMediaImageGetBits be used for the stream coming for ipp_capture_encode?

Is it possible to convert NvQueueGet to Mat?

Hi,
Is it possible to display the buffer(pBufferContext->output) pointing to an NvMediaImage in op_stream_handler.c(ipp_capture_encode) using OpenCV directly using the NvMediaGetImageBits as suggested earlier? Do I pass the buffer to Mat in opencv in order to display ? Do you think that the above mentioned method is possible?

raghavhrishi16,

Please share more about your pipeline(usecase). What process are you going to do with opencv mat?

I’m looking to display it using Mat (after copying the buffer in imagegetbits to mat)

I wonder why you don’t want to leverage ipp_raw or ipp_yuv. These two samples are able to display the NvMediaImage, so that there is no need to copy buffer to mat.

Could you describe why cannot use these two samples?

I would like to use OpenCV in the ipp_capture_encode because of the recording options that it provides. Can you please tell if the buffer copy to Mat is possible in ipp_capture_encode in order to display it using openCV?

I am also looking to feed the NvMediaImage to OpenCV in order to run my OpenCV algorithm and I would also like to display the live images from the camera on running the instruction. Could you please suggest an example for this or a way to possibly go about executing this?
Thanks

Yes, it is possible to use NvMediaImageGetBits to copy it to a memory. Please give it a try.

I believe above comment has pointed out some samples that use NvMediaImageGetBits as reference.

Is it sufficient to just copy it to a buffer using NvMediaImageGetBits or follow the entire process of finding the pitch and so on as done in save.c ? I am using ipp_capture_encode.
Keen to hear

You need to configure those attributes in _ConvRawToRgba before using NvMediaImageGetBits.