c++ - const T* const 指向特征矩阵

标签 c++ eigen

struct AscendReprojectionError {
    AscendReprojectionError(double observed_x, double observed_y)
        : observed_x(observed_x), observed_y(observed_y) {}

    template <typename T>
    bool operator()(const T* const camera,
        const T* const point,
        T* residuals) const {       

        Eigen::Matrix<T, 3, 3, Eigen::RowMajor> rot = Eigen::Map <Eigen::Matrix< T, 3, 3, Eigen::RowMajor> >(camera);

        return true;
    }

    // Factory to hide the construction of the CostFunction object from
    // the client code.
    static ceres::CostFunction* Create(const double observed_x,
        const double observed_y) {
        return (new ceres::AutoDiffCostFunction<AscendReprojectionError, 2, 9, 3>(
            new AscendReprojectionError(observed_x, observed_y)));
    }

    double observed_x;
    double observed_y;
};

如何在 const T* const point 中定义包含 9 个点的特征矩阵?以上是我失败的尝试

Error   3   error C2440: '<function-style-cast>' : cannot convert from 'const JetT *const ' to 'Eigen::Map<Derived,0,Eigen::Stride<0,0>>'   C:\dev\ceres-solver-1.8.0\examples\simple_bundle_adjuster.cc    133 1   simple_bundle_adjuster
Error   2   error C2440: '<function-style-cast>' : cannot convert from 'const double *const ' to 'Eigen::Map<Derived,0,Eigen::Stride<0,0>>' C:\dev\ceres-solver-1.8.0\examples\simple_bundle_adjuster.cc    133 1   simple_bundle_adjuster

评论中的问题:

class CostFunction {
 public:
  CostFunction() : num_residuals_(0) {}

  virtual ~CostFunction() {}

再次添加其余代码后。

报错如下。不确定它是否与 Eigen 有关,或者束调整器对我使用 Eigen 矩阵不满意。

Error   2   error C2039: 'epsilon' : is not a member of 'Eigen::NumTraits<ceres::Jet<T,12>>'    c:\dev\eigen-eigen-ffa86ffb5570\eigen\src\Core\IO.h 132 1   simple_bundle_adjuster

最佳答案

Eigen::Map用于包装 C 样式数组,以便它可以用作 Eigen::Matrix .通常,这允许它甚至写入底层数组。因为你只有一个 T const* , 不允许书写。为了保持 const-correct,您需要告诉 Eigen 映射禁止写入,因为您只有 T const*指针。为此,您指定 Map是一个const Matrix<...> .

template <typename T>
bool operator()(const T* const camera,
    const T* const point,
    T* residuals) const {

                                                          //   vvvvv
    Eigen::Matrix<T, 3, 3, Eigen::RowMajor> rot = Eigen::Map < const Eigen::Matrix< T, 3, 3, Eigen::RowMajor> >(camera);
    std::cout << rot << std::endl;                            
}

关于c++ - const T* const 指向特征矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23480617/

相关文章:

C++ 无序映射常量时间访问?

c++ - Z3 SMT Solver - 如何在 FPA 中提取 float 的值?

c++ - opencv中ocl模块的使用方法

c++装饰器模式,带模板的静态多态性和注册回调方法

c++ - 将 Matlab 的 bsxfun 转换为 Eigen

c++ - Eigen c++ 类型转换

c++ - 在 eigen 中使用 std::nth_element 和相关的询问

c++ - 为什么我们必须为 boost::get 提供参数类型?

c++ - 如何使用 MPI 在 Eigen::MatrixXd 中发送数据

c++ - Eigen 和 c++11 赋值和引用