Skip to content

Commit

Permalink
Consistent transform convention for CenterAndNormalizeImagePoints (co…
Browse files Browse the repository at this point in the history
  • Loading branch information
ahojnnes authored Aug 1, 2023
1 parent c1e43c0 commit 911779d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/colmap/estimators/essential_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ EssentialMatrixEightPointEstimator::Estimate(const std::vector<X_t>& points1,
// Center and normalize image points for better numerical stability.
std::vector<X_t> normed_points1;
std::vector<Y_t> normed_points2;
Eigen::Matrix3d points1_norm_matrix;
Eigen::Matrix3d points2_norm_matrix;
CenterAndNormalizeImagePoints(points1, &normed_points1, &points1_norm_matrix);
CenterAndNormalizeImagePoints(points2, &normed_points2, &points2_norm_matrix);
Eigen::Matrix3d normed_from_orig1;
Eigen::Matrix3d normed_from_orig2;
CenterAndNormalizeImagePoints(points1, &normed_points1, &normed_from_orig1);
CenterAndNormalizeImagePoints(points2, &normed_points2, &normed_from_orig2);

// Setup homogeneous linear equation as x2' * F * x1 = 0.
Eigen::Matrix<double, Eigen::Dynamic, 9> cmatrix(points1.size(), 9);
Expand All @@ -188,8 +188,8 @@ EssentialMatrixEightPointEstimator::Estimate(const std::vector<X_t>& points1,
const Eigen::Map<const Eigen::Matrix3d> ematrix_t(ematrix_nullspace.data());

// De-normalize to image points.
const Eigen::Matrix3d E_raw = points2_norm_matrix.transpose() *
ematrix_t.transpose() * points1_norm_matrix;
const Eigen::Matrix3d E_raw = normed_from_orig2.transpose() *
ematrix_t.transpose() * normed_from_orig1;

// Enforcing the internal constraint that two singular values must be equal
// and one must be zero.
Expand Down
10 changes: 5 additions & 5 deletions src/colmap/estimators/fundamental_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ FundamentalMatrixEightPointEstimator::Estimate(
// Center and normalize image points for better numerical stability.
std::vector<X_t> normed_points1;
std::vector<Y_t> normed_points2;
Eigen::Matrix3d points1_norm_matrix;
Eigen::Matrix3d points2_norm_matrix;
CenterAndNormalizeImagePoints(points1, &normed_points1, &points1_norm_matrix);
CenterAndNormalizeImagePoints(points2, &normed_points2, &points2_norm_matrix);
Eigen::Matrix3d normed_from_orig1;
Eigen::Matrix3d normed_from_orig2;
CenterAndNormalizeImagePoints(points1, &normed_points1, &normed_from_orig1);
CenterAndNormalizeImagePoints(points2, &normed_points2, &normed_from_orig2);

// Setup homogeneous linear equation as x2' * F * x1 = 0.
Eigen::Matrix<double, Eigen::Dynamic, 9> cmatrix(points1.size(), 9);
Expand Down Expand Up @@ -189,7 +189,7 @@ FundamentalMatrixEightPointEstimator::Estimate(
singular_values.asDiagonal() *
fmatrix_svd.matrixV().transpose();

return {points2_norm_matrix.transpose() * F * points1_norm_matrix};
return {normed_from_orig2.transpose() * F * normed_from_orig1};
}

void FundamentalMatrixEightPointEstimator::Residuals(
Expand Down
11 changes: 5 additions & 6 deletions src/colmap/estimators/homography_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ std::vector<HomographyMatrixEstimator::M_t> HomographyMatrixEstimator::Estimate(
// Center and normalize image points for better numerical stability.
std::vector<X_t> normed_points1;
std::vector<Y_t> normed_points2;
Eigen::Matrix3d points1_norm_matrix;
Eigen::Matrix3d points2_norm_matrix;
CenterAndNormalizeImagePoints(points1, &normed_points1, &points1_norm_matrix);
CenterAndNormalizeImagePoints(points2, &normed_points2, &points2_norm_matrix);
Eigen::Matrix3d normed_from_orig1;
Eigen::Matrix3d normed_from_orig2;
CenterAndNormalizeImagePoints(points1, &normed_points1, &normed_from_orig1);
CenterAndNormalizeImagePoints(points2, &normed_points2, &normed_from_orig2);

// Setup constraint matrix.
Eigen::Matrix<double, Eigen::Dynamic, 9> A = Eigen::MatrixXd::Zero(2 * N, 9);
Expand Down Expand Up @@ -86,8 +86,7 @@ std::vector<HomographyMatrixEstimator::M_t> HomographyMatrixEstimator::Estimate(
const Eigen::VectorXd nullspace = svd.matrixV().col(8);
Eigen::Map<const Eigen::Matrix3d> H_t(nullspace.data());

return {points2_norm_matrix.inverse() * H_t.transpose() *
points1_norm_matrix};
return {normed_from_orig2.inverse() * H_t.transpose() * normed_from_orig1};
}

void HomographyMatrixEstimator::Residuals(const std::vector<X_t>& points1,
Expand Down

0 comments on commit 911779d

Please sign in to comment.