woizzy 2023-02-23 12:25 采纳率: 45.5%
浏览 52

intel realsense深度相机点云转换为pcl点云

intel realsense深度相机拍摄的深度图获取的点云怎么转换为pcl点云类型
(暂定深度图获取转化为点云的方法为相机API中的calculate方法,有更好的点云方法可以用其他)
(vs2019+PCL+c++)

  • 写回答

1条回答 默认 最新

  • MarkHan_ 2023-02-23 12:32
    关注

    该回答引用GPTᴼᴾᴱᴺᴬᴵ
    要将Intel RealSense深度相机拍摄的深度图转换为PCL点云类型,需要执行以下步骤:

    1. 调用相机API中的calculate方法来获取深度图。
    2. 将深度图转换为PCL点云格式。可以使用PCL中的深度图像转换函数DepthImageToPointCloud。
    3. 可以选择对点云进行滤波,比如移动平均滤波,以降低噪声。可以使用PCL中的滤波函数。
    4. 可以将点云保存为PCL格式的点云文件(例如.pcd格式)。

    以下是示例代码:

    #include <iostream>
    #include <pcl/point_types.h>
    #include <pcl/visualization/cloud_viewer.h>
    #include <pcl/io/pcd_io.h>
    
    using namespace std;
    
    pcl::PointCloud<pcl::PointXYZ>::Ptr depthToPointCloud(rs2::depth_frame depth, rs2::intrinsics intrin)
    {
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
    
        float depthScale = rs2::context().get_device().first<rs2::depth_sensor>().get_depth_scale();
    
        // 获取深度图像的宽高
        int w = depth.get_width();
        int h = depth.get_height();
    
        // 遍历深度图像的像素
        for (int dy = 0; dy < h; ++dy)
        {
            for (int dx = 0; dx < w; ++dx)
            {
                // 获取深度图像的距离值
                float depthValue = depth.get_distance(dx, dy);
    
                // 跳过深度值为零的点
                if (depthValue == 0)
                {
                    continue;
                }
    
                // 计算点云坐标
                pcl::PointXYZ p;
                p.x = (dx - intrin.ppx) / intrin.fx * depthValue;
                p.y = (dy - intrin.ppy) / intrin.fy * depthValue;
                p.z = depthValue;
    
                // 将点云坐标添加到点云对象中
                cloud->push_back(p);
            }
        }
    
        return cloud;
    }
    
    int main()
    {
        // 获取实时深度图像和相机内参
        rs2::pipeline pipeline;
        pipeline.start();
        rs2::frameset frames = pipeline.wait_for_frames();
        rs2::depth_frame depth = frames.get_depth_frame();
        rs2::video_frame color = frames.get_color_frame();
        rs2_intrinsics intrin = depth.get_profile().as<rs2::video_stream_profile>().get_intrinsics();
    
        // 将深度图像转换为点云
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud = depthToPointCloud(depth, intrin);
    
        // 将点云保存为PCD文件
        pcl::io::savePCDFile("pointcloud.pcd", *cloud);
    
        // 可视化点云
        pcl::visualization::CloudViewer viewer("Point Cloud Viewer");
        viewer.showCloud(cloud);
    
        while (!viewer.wasStopped())
        {
        }
    
        return 0;
    }
    
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 2月23日

悬赏问题

  • ¥20 Wpf Datarid单元格闪烁效果的实现
  • ¥15 图像分割、图像边缘提取
  • ¥15 sqlserver执行存储过程报错
  • ¥100 nuxt、uniapp、ruoyi-vue 相关发布问题
  • ¥15 浮窗和全屏应用同时存在,全屏应用输入法无法弹出
  • ¥100 matlab2009 32位一直初始化
  • ¥15 Expected type 'str | PathLike[str]…… bytes' instead
  • ¥15 三极管电路求解,已知电阻电压和三级关放大倍数
  • ¥15 ADS时域 连续相位观察方法
  • ¥15 Opencv配置出错