【问题标题】:Converting Eigen::MatrixXd to pcl::PointCloud<pcl::PointXYZ>将 Eigen::MatrixXd 转换为 pcl::PointCloud<pcl::PointXYZ>
【发布时间】:2015-03-26 07:59:35
【问题描述】:

我的问题与Creating a PCL point cloud using a container of Eigen Vector3d 有关,但我使用的是Eigen::MatrixXd 而不是Eigen::Vector3dgetMatrixXfMap() 不是成员函数的一部分,因此不能代替 getVector3fMap() 使用。在这种情况下如何转换类型?

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

// resize to number of points
cloud->points.resize(Pts.rows());

/*DOES NOT WORK */
for(int i=0;i<Pts.rows();i++)
    cloud->points[i].getMatrixXfMap() = Pts[i].cast<float>();

【问题讨论】:

    标签: eigen point-cloud-library


    【解决方案1】:

    它可能不是很性感,但为什么不在你的 for 循环中创建每个点呢?在这种情况下不需要调整大小。

    pcl::PointXYZ temp;
    temp.x = Pts[i][0];
    temp.y = Pts[i][1];
    temp.z = Pts[i][2];
    cloud.push_back(temp);
    

    【讨论】:

    • 确实,一点都不性感
    【解决方案2】:

    这就是我所做的。我的source_cloud 是一个 Nx3 矩阵,包含 float32 格式的 XYZ 点。

    typedef pcl::PointCloud<pcl::PointXYZRGBA> PointCloudRGBA;
    
    Eigen::MatrixXf convertToPointCloud(const Eigen::MatrixXf source_cloud){
        PointCloudRGBA::Ptr cloud(new PointCloudRGBA);
        cloud->points.resize(source_cloud.rows());
        for(int i=0; i<source_cloud.rows(); i++){
            cloud->points[i].getVector3fMap() = Eigen::Vector3d(source_cloud(i, 0), source_cloud(i, 1), source_cloud(i, 2)).cast<float>();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-15
      • 2021-03-12
      • 2020-07-31
      • 2015-12-07
      相关资源
      最近更新 更多