首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Eigen::MatrixXd转换为pcl::PointCloud<pcl::PointXYZ>

将Eigen::MatrixXd转换为pcl::PointCloud<pcl::PointXYZ>
EN

Stack Overflow用户
提问于 2015-01-28 00:14:48
回答 2查看 1.5K关注 0票数 0

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

代码语言:javascript
复制
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>();
EN

回答 2

Stack Overflow用户

发布于 2015-02-12 12:25:57

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

代码语言:javascript
复制
pcl::PointXYZ temp;
temp.x = Pts[i][0];
temp.y = Pts[i][1];
temp.z = Pts[i][2];
cloud.push_back(temp);
票数 1
EN

Stack Overflow用户

发布于 2021-11-17 09:16:34

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

代码语言:javascript
复制
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>();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28174974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档