Description
As part of run_reconstruction
, the data for images.bin
, cameras.bin
, and points3D.bin
for the largest reconstruction is supposed to be moved to sfm_dir
. However, this does not happen reliably when COLMAP produces multiple models.
This is because the models in the numbered folders created by COLMAP (models/0
, models/1
, etc.) are not guaranteed to be in the same order as the reconstructions
list returned by COLMAP.
COLMAP numbers the folders based on the count of points3D
so that the folder 0
always has the model with the largest number of points and this is different than the order of the reconstructions
list: https://github.com/colmap/colmap/blob/db14f5c59bdaa5239b804ff4623f2fb8e5bb2a46/src/colmap/scene/reconstruction_manager.cc#L60-L83
void ReconstructionManager::Write(const std::string& path) const {
std::vector<std::pair<size_t, size_t>> recon_sizes(reconstructions_.size());
for (size_t i = 0; i < reconstructions_.size(); ++i) {
recon_sizes[i] = std::make_pair(i, reconstructions_[i]->NumPoints3D());
}
std::sort(recon_sizes.begin(),
recon_sizes.end(),
[](const std::pair<size_t, size_t>& first,
const std::pair<size_t, size_t>& second) {
return first.second > second.second;
});
for (size_t i = 0; i < reconstructions_.size(); ++i) {
const std::string reconstruction_path = JoinPaths(path, std::to_string(i));
CreateDirIfNotExists(reconstruction_path);
reconstructions_[recon_sizes[i].first]->Write(reconstruction_path);
}
}
This difference causes an issue in run_reconstruction
where the data that is moved does not correspond to the model of the largest_index
:
Hierarchical-Localization/hloc/reconstruction.py
Lines 99 to 103 in b21ff20
Forcing largest_index
to always be 0
resolves the issue, but is different behavior than before.
It looks like this issue was introduced as part of hloc 1.3 because before hloc 1.3, the logic involved iterating directly over the model folders 55e6cde#diff-1415a09ff92c2b9e2091340b072a454b63b9b7422a63f363dc6c2dcce7349769:
Hierarchical-Localization/hloc/reconstruction.py
Lines 81 to 96 in 9bad6b4