2016-05-22 8 views
0

Features2D + Homography to find a known objectと同様の方法で画像を比較しようとしましたが、findHomography()の代わりにfindAffine()機能を使用してください。ceres solver resultから異常値を取り出す方法は?

私は、外れ値を考慮して最適なアフィン行列を得るために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); 

セレスソルバLossFunctionを提供する:

損失関数は、通常のものは、外れ値に対応し、高い残差と残差ブロックの影響を低減します。

もちろん、キーポイント座標を取得した行列で最初の画像から変換し、秒と比較して偏差を得ることができます。しかし、作業中にすでに解決策を完了しています。

どのように取得できますか?ドキュメントでそれを見つけられませんでした。

+0

なぜ誰かが私に説明を下す理由はありますか? – victor1234

答えて

2

私にも同様の問題がありました。 Ceresライブラリのソース(特にResidualBlock :: Evaluate()メソッド)を調べた結果、残余ブロックの明示的な "異常値"の状態がないという結論が得られました。損失関数は、ブロックの結果コスト値に影響するように見えます(これは、引用符で囲んだドキュメントのフレーズで正確に記述されています - 「損失関数は残差の高い残差ブロックの影響を減らします)。答えはあなたが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; 
関連する問題