8000 Compute reprojection error in generalized absolute solver by sarlinpe · Pull Request #1257 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Compute reprojection error in generalized absolute solver #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/estimators/generalized_absolute_pose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,21 @@ void GP3PEstimator::Residuals(const std::vector<X_t>& points2D,

const double x_0 = points2D[i].xy(0);
const double x_1 = points2D[i].xy(1);
const double inv_x_norm = 1 / std::sqrt(x_0 * x_0 + x_1 * x_1 + 1);

const double cosine_dist =
1 - inv_pcx_norm * inv_x_norm * (pcx_0 * x_0 + pcx_1 * x_1 + pcx_2);
(*residuals)[i] = cosine_dist * cosine_dist;

if (residual_type == ResidualType::CosineDistance) {
const double inv_x_norm = 1 / std::sqrt(x_0 * x_0 + x_1 * x_1 + 1);
const double cosine_dist =
1 - inv_pcx_norm * inv_x_norm * (pcx_0 * x_0 + pcx_1 * x_1 + pcx_2);
(*residuals)[i] = cosine_dist * cosine_dist;
} else if (residual_type == ResidualType::ReprojectionError) {
const double inv_pcx_2 = 1.0 / pcx_2;
const double dx_0 = x_0 - pcx_0 * inv_pcx_2;
const double dx_1 = x_1 - pcx_1 * inv_pcx_2;
const double reproj_error = dx_0 * dx_0 + dx_1 * dx_1;
(*residuals)[i] = reproj_error;
} else {
LOG(FATAL) << "Invalid residual type";
}
} else {
(*residuals)[i] = std::numeric_limits<double>::max();
}
Expand Down
17 changes: 14 additions & 3 deletions src/estimators/generalized_absolute_pose.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class GP3PEstimator {
// The minimum number of samples needed to estimate a model.
static const int kMinNumSamples = 3;

enum class ResidualType {
CosineDistance,
ReprojectionError,
};

// Whether to compute the cosine similarity or the reprojection error.
// [WARNING] The reprojection error being in normalized coordinates,
// the unique error threshold of RANSAC corresponds to different pixel values
// in the different cameras of the rig if they have different intrinsics.
ResidualType residual_type = ResidualType::CosineDistance;

// Estimate the most probable solution of the GP3P problem from a set of
// three 2D-3D point correspondences.
static std::vector<M_t> Estimate(const std::vector<X_t>& points2D,
Expand All @@ -77,9 +88,9 @@ class GP3PEstimator {
// Calculate the squared cosine distance error between the rays given a set of
// 2D-3D point correspondences and a projection matrix of the generalized
// camera.
static void Residuals(const std::vector<X_t>& points2D,
const std::vector<Y_t>& points3D,
const M_t& proj_matrix, std::vector<double>* residuals);
void Residuals(const std::vector<X_t>& points2D,
const std::vector<Y_t>& points3D,
const M_t& proj_matrix, std::vector<double>* residuals);
};

} // namespace colmap
Expand Down
6 changes: 3 additions & 3 deletions src/estimators/generalized_absolute_pose_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ BOOST_AUTO_TEST_CASE(Estimate) {

// Test residuals of exact points.
std::vector<double> residuals;
GP3PEstimator::Residuals(points2D, points3D, report.model, &residuals);
ransac.estimator.Residuals(points2D, points3D, report.model, &residuals);
for (size_t i = 0; i < residuals.size(); ++i) {
BOOST_CHECK(residuals[i] < 1e-10);
}

// Test residuals of faulty points.
GP3PEstimator::Residuals(points2D, points3D_faulty, report.model,
&residuals);
ransac.estimator.Residuals(points2D, points3D_faulty, report.model,
&residuals);
for (size_t i = 0; i < residuals.size(); ++i) {
BOOST_CHECK(residuals[i] > 1e-10);
}
Expand Down
0