c++ - 将 pcl::PointCloud 转换为 Eigen::MatrixBase

标签 c++ matrix eigen point-cloud-library

我正在尝试从 this 运行 ICP 算法 header 。第 260 行的函数声明为

template <typename Derived1, typename Derived2>
void point_to_point(Eigen::MatrixBase<Derived1>& X,
                    Eigen::MatrixBase<Derived2>& Y,
                    Parameters par = Parameters()) {

我想在我的两个 pcl::PointCloud 上应用这个算法s 但它接受 Eigen::MatrixBase .我试着按如下方式调用这个函数

Eigen::MatrixBase<Eigen::Matrix<double,3,1,Eigen::RowMajor,3,100>> X;
Eigen::MatrixBase<Eigen::Matrix<double,3,1,Eigen::RowMajor,3,100>> Y;
Parameters par = Parameters()
point_to_point(X,Y,Parameters)

它给了我这个错误

error: ‘Eigen::MatrixBase<Derived>::MatrixBase() [with Derived = Eigen::Matrix<double, 3, 1, 1, 3, 100>]’ is protected
     MatrixBase() : Base() {}

我也试过Eigen::MatrixBase<Eigen::Matrix4f> X;但是每种类型似乎都受到保护。具体是什么意思?

我搜索了很多但没有找到 MatrixBase 的任何例子.

  • 如何在 Eigen::MatrixBase 中插入/删除值- 没有找到任何这样的功能 here
  • 如何转换我的 pcl::PointCloudEigen::MatrixBase并反转?
  • 如何调用这个函数?

最佳答案

您可以使用 for 循环构造矩阵。例如

Eigen::Matrix3Xd X, Y;
    for (size_t idx = 0; idx != pc_X->size(); ++idx) {
        X.col(idx) = Eigen::Vector3d{pc_X->at(idx).x, 
                    pc_X->at(idx).y, 
                    pc_X->at(idx).z};
    }
    for (size_t idx = 0; idx != pc_Y->size(); ++idx) {
        Y.col(idx) = Eigen::Vector3d{pc_Y->at(idx).x, pc_Y->at(idx).y, pc_Y->at(idx).z};
    }

关于c++ - 将 pcl::PointCloud 转换为 Eigen::MatrixBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28129537/

相关文章:

c++ - 使用精度规则 c++ 排列表格

c++ - C++ 中有限域元素的平方根

arrays - 确定单个单元格中两个矩阵的最大值

c - 在C编程中需要将每个3个矩阵中的3个最大数字放入1个单矩阵中

c++ - Eigen 和 CImg 兼容性问题

c++ - Eigen 张量广播语法

c++ - 列出gdb中类的所有功能

python - 如何用现有的 xyz 数据制作矩阵

c++ - 使用 Pybind11 将 Eigen::Tensor 暴露给 Python

c++ - Valgrind 挂起,没有输出