UnaNancyOwen
3/14/2016 - 2:09 PM

Convert to cv::Mat from pcl::PointCloud<pcl::PointXYZRGBA> that retrieved from Kinect v1/v2 sensor using KinectGrabber/Kinect2Grabber

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;
        }
    }
}