I have a CUDA kernel file
I want to pass unsigned char* directly from CU files to opencv cv::cuda::gpumat
In one of the sample(v4l2cuda) , in multimedia api,
in capture.cpp,
there is a function (to call cuda kernel) for passing the V4L2 userptr
static unsigned char * cuda_out_buffer = NULL;
static void process_image (void *p){
gpuConvertYUYVtoRGB ((unsigned char *) p, cuda_out_buffer, width, height);
}
process_image ((void *) buf.m.userptr);
and I suppose it works allright, because I got an Image by using this cuda_out_buffer pointer
FILE *fp = fopen (“cu.ppm”, “wb”);
fprintf (fp, “P6\n%u %u\n255\n”, width, height);
fwrite (cuda_out_buffer, 1, width * height * 3, fp); //got an image
fclose (fp);
myapp.cpp:
//function to get cuda_out_buffer from capure.cpp
unsigned char* getcudaptr;
fromCU(&getcudaptr, bytes_used, width, height);//function to get cuda_out_buffer from capure.cpp
capture.cpp:
//now I passed cuda_out_buffer to my opencv file myapp.cpp, by using getcudaptr
void fromCU(unsigned char **setcudaptr, int bytes_used,int width, int height){
*setcudaptr = cuda_out_buffer;
}
myapp.cpp:
FILE *fp = fopen (“fromcudaptr.ppm”, “wb”); //this works, I got the same image
fprintf (fp, “P6\n%u %u\n255\n”, width, height);
fwrite (getcudaptr, 1, width * height * 3, fp);
fclose (fp);
now I intent to pass cuda_out_buffer, directly to cv::cuda::GpuMat,
so, I did
cv::cuda::GpuMat <b>gpu_src</b>;
gpu_src.create(height, width, CV_8UC3);
gpu_src.data = getcudaptr; //passing the pointer to opencv gpumat
FILE *fp = fopen ("gpu_src_data.ppm", "wb");
fprintf (fp, "P6\n%u %u\n255\n", width, height);
fwrite (gpu_src.data, 1, width * height * 3, fp); //gpu_src.data gives the same image output as, getcudaptr & cuda_out_buffer
fclose (fp);
then,
imshow(“OpenCV V4L2”, gpu_src);
//gives error:
///home/is/src/opencv-3.4.6/modules/core/src/opengl.cpp:230: error: (-217:Gpu API call) invalid argument in function ‘copyFrom’
why I am to able to save the image by fopen/fwrite, but not able to display it using imshow( I have tested, imshow+opengl, works for mat->upload->gpumat->imshow )
or is my poor handling during creating the gpusrc header?