Skip to content
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

Fix conversion of colmap pose prior #57

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions glomap/estimators/global_rotation_averaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ bool RotationEstimator::EstimateRotations(
image.cam_from_world.rotation = Eigen::Quaterniond(AngleAxisToRotation(
rotation_estimated_.segment(image_id_to_idx_[image_id], 3)));
}
// Restore the prior position (t = -Rc = R * R_ori * t_ori = R * t_ori)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R * R_ori * t_ori = R * t_ori
The equation only holds when R_ori is identity.
However, EstimateRotations will be called twice in GlobalMapper::Solve.

image.cam_from_world.translation =
(image.cam_from_world.rotation * image.cam_from_world.translation);
}

return true;
Expand Down
21 changes: 10 additions & 11 deletions glomap/io/colmap_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,15 @@ void ConvertDatabaseToGlomap(const colmap::Database& database,
<< images_colmap.size() << std::flush;
counter++;

image_t image_id = image.ImageId();
const image_t image_id = image.ImageId();
if (image_id == colmap::kInvalidImageId) continue;
auto ite = images.insert(std::make_pair(
image_id, Image(image_id, image.CameraId(), image.Name())));
const colmap::PosePrior prior = database.ReadPosePrior(image_id);
if (prior.IsValid()) {
ite.first->second.cam_from_world = Rigid3d(
colmap::Rigid3d(Eigen::Quaterniond::Identity(), prior.position));
const colmap::Rigid3d world_from_cam_prior(Eigen::Quaterniond::Identity(),
prior.position);
ite.first->second.cam_from_world = Rigid3d(Inverse(world_from_cam_prior));
} else {
ite.first->second.cam_from_world = Rigid3d();
}
Expand All @@ -200,20 +201,18 @@ void ConvertDatabaseToGlomap(const colmap::Database& database,

// Read keypoints
for (auto& [image_id, image] : images) {
colmap::FeatureKeypoints keypoints = database.ReadKeypoints(image_id);

image.features.reserve(keypoints.size());
for (int i = 0; i < keypoints.size(); i++) {
image.features.emplace_back(
Eigen::Vector2d(keypoints[i].x, keypoints[i].y));
const colmap::FeatureKeypoints keypoints = database.ReadKeypoints(image_id);
const int num_keypoints = keypoints.size();
image.features.resize(num_keypoints);
for (int i = 0; i < num_keypoints; i++) {
image.features[i] = Eigen::Vector2d(keypoints[i].x, keypoints[i].y);
}
}

// Add the cameras
std::vector<colmap::Camera> cameras_colmap = database.ReadAllCameras();
for (auto& camera : cameras_colmap) {
camera_t camera_id = camera.camera_id;
cameras[camera_id] = camera;
cameras[camera.camera_id] = camera;
}

// Add the matches
Expand Down