Convert VPIImage to cv::cuda::GpuMat

How to convert VPIImage to cv::cuda::GpuMat ?

There is already an example to convert cv::cuda::GpuMat to VPIImage here :

I would like to see how to convert/wrap the other way around.

I think the only way is to create the image outside of VPI, e.g. cudaMalloc, and wrap it with vpiImageCreateCUDAMemWrapper or similar.

Sorry, I dont understand your answer,
I already have an VPIImage (in my case wraped from a NVBuffer).

First I want to do some processing with my VPIImage (color conversion etc.) with PVA.

After that I want to use some cv:cuda algorithmes, so I need VPIImage to cv::cuda::GpuMat.

There is currently no way to “convert” from a VPI image to any other type I guess, you can wrap existing memory however that is modified by VPI algorithms.

Say you want to convert the image you got from a NvBuffer using VPI and then process the converted image in CUDA you could do:

  1. convert NvBuffer to VPI image as src image
  2. create/allocate cv::cuda::GpuMat and wrap device pointer with vpiImageCreateCUDAMemWrapper as dst image
  3. call VPI image conversion algorithm with src and dst
  4. synchronize VPI

Then you can continue to use your converted image inside OpenCV

Ok, I understand. Thank you for the quick response and the suggested solution.