PCL:深度图转点云

cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
    // 创建点云对象

    // 读取深度图像
    cv::Mat depthImage = cv::imread(fullFilename, cv::IMREAD_UNCHANGED);
    depthImage.convertTo(depthImage, CV_32FC1);

    // 遍历深度图像,将符合条件的点添加到点云中
    float minDepth = 0.1;  // 最小深度阈值(单位:米)
    float maxDepth = 3.0;  // 最大深度阈值(单位:米)
    for (int y = 0; y < depthImage.rows; ++y)
    {
        for (int x = 0; x < depthImage.cols; ++x)
        {
            // 获取深度值
            float depth = depthImage.at<float>(y, x);

            // 忽略深度值为0的点
            if (depth == 0)
                continue;

             如果深度值不在指定的范围内,则忽略该点
            //if (depth < minDepth || depth > maxDepth)
            //    continue;

            // 计算三维坐标
            double X = (x - cx) * depth / fx;
            double Y = (y - cy) * depth / fy;
            double Z = -depth;

            // 创建点云点并设置坐标
            pcl::PointXYZ point;
            point.x = X;
            point.y = Y;
            point.z = Z;

            // 将点添加到点云中
            cloud->push_back(point);
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值