cv :: Mat to pcl :: PointCloud,数据为unsigned short *?

时间:2017-10-12 14:12:20

标签: c++ opencv point-cloud-library point-clouds

我有cv::Mat深度图片。

我正在将它转换为PCL点云,如下所示:

PointCloud::Ptr RGBDtoPCL3(cv::Mat depth_image)
{
    PointCloud::Ptr pointcloud(new PointCloud);

    float fx = 481.20;
    float fy = 480.00;
    float cx = 319.50;
    float cy = 239.50;

    float factor = 1;
    depth_image.convertTo(depth_image, CV_32F); // convert the image data to float type 

    if (!depth_image.data) {
        std::cerr << "No depth data!!!" << std::endl;
        exit(EXIT_FAILURE);
    }

    pointcloud->width = depth_image.cols; //Dimensions must be initialized to use 2-D indexing 
    pointcloud->height = depth_image.rows;

    pointcloud->points.resize(pointcloud->height * pointcloud->width);
    pointcloud->resize(pointcloud->width*pointcloud->height);

    for (int v = 0; v < depth_image.rows; v++)
    {
        for (int u = 0; u < depth_image.cols; u++)
        {
            float Z = depth_image.at<float>(v, u) / factor;

            PointT p;
            p.z = Z;
            p.x = (u - cx) * Z / fx;
            p.y = (v - cy) * Z / fy;

            p.z = p.z / 1000;
            p.x = p.x / 1000;
            p.y = p.y / 1000;

            pointcloud->points.push_back(p);

        }
    }

    return pointcloud;

}

我也从Mat获取数据:

unsigned short* dataMat1 = depth_image.ptr<unsigned short>();

然后我在点云上做了一些处理。

我现在需要做的是将pointcloud转换为与上面的dataMat1匹配的无符号短*。

这种转换会是什么样的?我是否需要转换回cv::Mat然后使用其ptr?或者我可以从pointcloud转换为unsigned short *?

谢谢。

0 个答案:

没有答案