Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to convert openni stream data to cv::gpumat

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.

How to convert openni stream data to cv::gpumat

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_);
color_.readFrame(&colorf_); // color_ is 480rows*640cols

// 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.

How to convert openni stream data to cv::gpumat

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 directly to a gpumat. gpumat (without copying to cv::Mat). 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_); // color_ is 480rows*640cols

// 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 cudamemcpy2d as I have copied the same data to cv::Mat using memcpy and viewed the correct images.

images with code snippet as below:

cv::Mat colorf_opencv;
color_.readFrame(&colorf_);
const openni::RGB888Pixel* imageBuffer_col = (const openni::RGB888Pixel*)colorf_.getData();

colorf_opencv.create(colorf_.getHeight(), colorf_.getWidth(), CV_8UC3);
memcpy( colorf_opencv.data, imageBuffer_col, 3*colorf_.getHeight()*colorf_.getWidth()*sizeof(uint8_t) );