Skip to content

Instantly share code, notes, and snippets.

@UnaNancyOwen
Last active December 27, 2022 14:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save UnaNancyOwen/40195f32a9ad4fa09ac5 to your computer and use it in GitHub Desktop.
Save UnaNancyOwen/40195f32a9ad4fa09ac5 to your computer and use it in GitHub Desktop.
Convert to cv::Mat from pcl::PointCloud<pcl::PointXYZRGBA> that retrieved from Kinect v1/v2 sensor using KinectGrabber/Kinect2Grabber
if( !cloud->empty() ){
// Create cv::Mat
image = cv::Mat( cloud->height, cloud->width, CV_8UC4 );
// pcl::PointCloud to cv::Mat
#pragma omp parallel for
for( int y = 0; y < image.rows; y++ ) {
for( int x = 0; x < image.cols; x++ ) {
pcl::PointXYZRGBA point = cloud->at( x, y );
image.at<cv::Vec4b>( y, x )[0] = point.b;
image.at<cv::Vec4b>( y, x )[1] = point.g;
image.at<cv::Vec4b>( y, x )[2] = point.r;
image.at<cv::Vec4b>( y, x )[3] = point.a;
}
}
}
@UnaNancyOwen
Copy link
Author

@jediofgever
Copy link

maybe should be
auto image = cv::Mat( cloud->height, cloud->width, CV_8UC4 ); ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment