const T* const 点到特征矩阵

Pou*_*sen 2 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;
};
Run Code Online (Sandbox Code Playgroud)

如何定义包含 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
Run Code Online (Sandbox Code Playgroud)

评论中的问题:

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

  virtual ~CostFunction() {}
Run Code Online (Sandbox Code Playgroud)

再次添加其余代码后。

给出以下错误。不确定它是否与特征有关,或者捆绑调整器对我使用特征矩阵不满意。

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
Run Code Online (Sandbox Code Playgroud)

Dav*_*e S 5

Eigen::Map用于包装 C 样式数组,以便它可以用作Eigen::Matrix. 通常,这甚至允许它写入底层数组。由于您只有一个T const*,因此不允许写入。为了保持常量正确,您需要告诉 Eigen 映射禁止写入,因为您只有T const*指针。为此,您将 is 指定Map为 a 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;                            
}
Run Code Online (Sandbox Code Playgroud)