2016-05-22 23 views
0

我嘗試使用類似於Features2D + Homography to find a known object的方法比較圖像,但用自編的findAffine()函數代替findHomography()如何從ceres解算器結果中檢索異常值?

我使用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

損失函數減少殘餘塊的影響具有高的殘差,通常對應於異常值的那些。

當然,我可以通過獲得矩陣轉換第一幅圖像的關鍵點座標,與第二幅圖像進行比較並得到偏差。但是Ceres求解器在工作中已經完成了它。

我如何檢索它?沒有在文檔中找到它。

+0

任何人都可以解釋爲什麼問題是downvoted? – 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;