jetson-utils icon indicating copy to clipboard operation
jetson-utils copied to clipboard

Convert/map uchar3* to cv::cuda::GpuMat

Open poett1 opened this issue 1 year ago • 1 comments

Hello, i am developing a CV application based on jetson-utils. In my video pipeline i need to use at least one cv::cuda function that expects a cv::cuda::GpuMat as input/output. It works fine this way:

uchar3` *image = NULL;
videoSource *input = videoSource::Create("v4l2:///dev/video4", opt);
 input->Capture(&image, 1000);
 cv::cuda::GpuMat frame_now(input->GetHeight(), input->GetWidth(), CV_8UC3, image);

But not in this example:

uchar3` *image = NULL;
uchar3* imgOutput = NULL;
videoSource *input = videoSource::Create("v4l2:///dev/video4", opt);
 input->Capture(&image, 1000);

if( !cudaAllocMapped(&imgOutput, input->GetWidth(), input->GetHeight()) )
	return false;

CUDA(cudaNormalize(image, make_float2(0,255),
                   imgOutput, make_float2(0,1),
                    input->GetWidth(), input->GetHeight()));
 cv::cuda::GpuMat frame_now(input->GetHeight(), input->GetWidth(), CV_8UC3, imgOutput);

Whats the difference in allocation here? Is image still captured into CPU Memory in the first example and not allocated to CUDA memory? Is there a common way to convert/map an uchar3* image buffer allocated on GPU with cudaAllocMapped() into a GpuMat?

Thanks a lot!

poett1 avatar Aug 01 '22 15:08 poett1

Are you sure it doesn't have to do with the cudaNormalize() call?

cudaAllocMapped() allocates shared CPU/GPU memory, so it should be the same - what is the error you are getting?

dusty-nv avatar Aug 01 '22 19:08 dusty-nv