Skip to content

Conversation

@lpanaf
Copy link
Collaborator

@lpanaf lpanaf commented Jan 12, 2026

A heuristic fix for the id mismatch for the old colmap database. Previously, frame_id / rig_id are randomly assigned when they do not exist in database, now set it to be consistent with the image_id / camera_id.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses ID mismatch issues when converting old COLMAP databases to GLOMAP format. The fix ensures that when frame_id or rig_id don't exist in the database, they are assigned values consistent with image_id or camera_id respectively, rather than being randomly incremented.

Changes:

  • Modified rig ID assignment logic to use camera_id when no existing rigs are present
  • Modified frame ID assignment logic to use image_id when no existing frames are present

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (cameras_id_to_rig_id.find(camera_id) == cameras_id_to_rig_id.end()) {
Rig rig;
rig.SetRigId(++max_rig_id);
if (max_rig_id != 0)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

ID collision bug: When max_rig_id equals 0 but a rig with ID 0 exists in the database, using camera_id directly can cause a collision. For example, if there's an existing rig with ID 0, and a new camera has camera_id=0, this will create a duplicate rig ID. The condition should check whether any rigs exist, not just whether max_rig_id is non-zero. Consider using rigs.empty() or always incrementing from max_rig_id.

Suggested change
if (max_rig_id != 0)
// If any rigs already exist, assign a new unique rig ID by incrementing
// the current maximum. Otherwise, for the very first rig, reuse the
// camera_id as the rig ID to preserve original behavior.
if (!rigs.empty())

Copilot uses AI. Check for mistakes.
for (auto& [image_id, image] : images) {
if (image.frame_id == colmap::kInvalidFrameId) {
frame_t frame_id = ++max_frame_id;
frame_t frame_id = (max_frame_id > 0)? ++max_frame_id : image_id;
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

ID collision bug: When max_frame_id equals 0 but a frame with ID 0 exists in the database, using image_id directly can cause a collision. For example, if there's an existing frame with ID 0, and an image has image_id=0, this will create a duplicate frame ID. Consider checking frames.empty() or always incrementing from max_frame_id to avoid collisions.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants