gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:17:52 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com