gpt4 book ai didi

c++ - 如何从 ceres 求解器结果中检索异常值?

转载 作者:行者123 更新时间:2023-11-30 02:31:41 24 4
gpt4 key购买 nike

我尝试使用类似于 Features2D + Homography to find a known object 的方法比较图像而是将findHomography()替换为自己编写的findAffine()函数。

我使用 Ceres Solver获得考虑异常值的最佳仿射矩阵。

    double translation[] = {0, 0};
double angle = 0;
double scaleFactor = 1;

ceres::Problem problem;


for (size_t i = 0; i < points1.size(); ++i) {
problem.AddResidualBlock(
new ceres::AutoDiffCostFunction<AffineResidual, 1, 2, 1, 1>(
new AffineResidual(Eigen::Vector2d(points1[i].x, points1[i].y),
Eigen::Vector2d(points2[i].x, points2[i].y))),
new ceres::HuberLoss(1.0),
translation,
&angle,
&scaleFactor);
}

ceres::Solver::Options options;
options.linear_solver_type = ceres::DENSE_QR;
options.minimizer_progress_to_stdout = true;

ceres::Solver::Summary summary;
Solve(options, &problem, &summary);

Ceres 求解器提供 LossFunction :

Loss functions reduce the influence of residual blocks with high residuals, usually the ones corresponding to outliers.

当然,我可以通过获得的矩阵转换第一张图像的关键点坐标,与第二张图像进行比较并得到偏差。但是 ceres 求解器已经在工作期间在内部完成了。

我如何找回它?在文档中没有找到它。

最佳答案

我遇到了类似的问题。在查看 Ceres 库资源(特别是 ResidualBlock::Evaluate() 方法)后,我得出结论,残差 block 没有明确的“异常值”状态。损失函数似乎只影响 block 的最终成本值(这正是您引用的文档中的短语所描述的 - “损失函数减少了具有高残差的残差 block 的影响”)。所以答案是你无法从 Ceres 中检索异常值,没有这样的功能。

解决方法可能是使用求解结果计算数据的残差,并对它们应用损失函数。来自 LossFunction::Evaluate() 的评论可能会有所帮助:

// For a residual vector with squared 2-norm 'sq_norm', this method
// is required to fill in the value and derivatives of the loss
// function (rho in this example):
//
// out[0] = rho(sq_norm),
// out[1] = rho'(sq_norm),
// out[2] = rho''(sq_norm),
//
// Here the convention is that the contribution of a term to the
// cost function is given by 1/2 rho(s), where
//
// s = ||residuals||^2.
//
// Calling the method with a negative value of 's' is an error and
// the implementations are not required to handle that case.
//
// Most sane choices of rho() satisfy:
//
// rho(0) = 0,
// rho'(0) = 1,
// rho'(s) < 1 in outlier region,
// rho''(s) < 0 in outlier region,
//
// so that they mimic the least squares cost for small residuals.
virtual void Evaluate(double sq_norm, double out[3]) const = 0;

关于c++ - 如何从 ceres 求解器结果中检索异常值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37379557/

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