Features2D + Homographyと同様の方法を使用して画像を比較し、既知のオブジェクトを見つけようとしますが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を提供します:
損失関数は、高い残差 (通常は外れ値に対応するもの) を持つ残差ブロックの影響を減らします。
もちろん、取得した行列を使用して最初の画像からキーポイント座標を変換し、2 番目の画像と比較して偏差を取得できます。しかし、セレスソルバーは作業中にすでに内部でそれを行っています。
どうすれば取得できますか? ドキュメントには見つかりませんでした。