As per stackoverflow openni questionThe data in the openni RGB888Pixel array can be interpreted as a uchar 1 dimension array of size heightwidth3. Each uchar of this array will tell you the red, green or blue value of each pixel. The order would be by rows and rgb, so the array will be something like
r_1,g_1,b_1,r_2,g_2,b2.....
I need to copy this data directly to a gpumat. How do I do it?
I tried as below, but when I try to download the gpumat to cv::Mat I get error OpenCV Error:
The function/feature is not implemented (You should explicitly call download method for cuda::GpuMat object) in getMat_, file /home/krr/softwares/opencv-3.1.0/modules/core/src/matrix.cpp, line 1224
terminate called after throwing an instance of 'cv::Exception'
what(): /home/krr/softwares/opencv-3.1.0/modules/core/src/matrix.cpp:1224: error: (-213) You should explicitly call download method for cuda::GpuMat object in function getMat_
Aborted (core dumped)
My code snippet:
// the destination gpumat
cv::Mat colorf_opencv(480,640, CV_8UC3);
openni::VideoStream color_;
color_.readFrame(&colorf_);
// This is the data that needs to be copied to the gpumat
const openni::RGB888Pixel* imageBuffer_col = (const openni::RGB888Pixel*)colorf_.getData();
cudaMemcpy2D( (void *)colorf_opencv.data, 640*sizeof(uchar3),
(void*)imageBuffer_col,3*640*sizeof(uchar),3*640*sizeof(uchar),480, cudaMemcpyHostToDevice );
The error is the cudamemcpy2d as I have copied the same data to cv::Mat using memcpy and viewed the correct images.