Skip to content

Commit 5de87aa

Browse files
ParameterizeVariables returns false when no active poses are found, rather than failing inside ceres
1 parent 262e122 commit 5de87aa

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

glomap/estimators/bundle_adjustment.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "bundle_adjustment.h"
22

3+
#include <optional>
4+
35
#include <colmap/estimators/cost_functions.h>
46
#include <colmap/estimators/manifold.h>
57
#include <colmap/sensor/models.h>
@@ -33,7 +35,9 @@ bool BundleAdjuster::Solve(const ViewGraph& view_graph,
3335
AddCamerasAndPointsToParameterGroups(cameras, images, tracks);
3436

3537
// Parameterize the variables
36-
ParameterizeVariables(cameras, images, tracks);
38+
if (!ParameterizeVariables(cameras, images, tracks)) {
39+
return false;
40+
}
3741

3842
// Set the solver options.
3943
ceres::Solver::Summary summary;
@@ -180,25 +184,25 @@ void BundleAdjuster::AddCamerasAndPointsToParameterGroups(
180184
}
181185
}
182186

183-
void BundleAdjuster::ParameterizeVariables(
187+
bool BundleAdjuster::ParameterizeVariables(
184188
std::unordered_map<camera_t, Camera>& cameras,
185189
std::unordered_map<image_t, Image>& images,
186190
std::unordered_map<track_t, Track>& tracks) {
187-
image_t center;
188-
189191
// Parameterize rotations, and set rotations and translations to be constant
190192
// if desired FUTURE: Consider fix the scale of the reconstruction
191-
int counter = 0;
193+
std::optional<image_t> center;
192194
for (auto& [image_id, image] : images) {
193195
if (problem_->HasParameterBlock(
194196
image.cam_from_world.rotation.coeffs().data())) {
195197
colmap::SetQuaternionManifold(
196198
problem_.get(), image.cam_from_world.rotation.coeffs().data());
197199

198-
if (counter == 0) {
200+
if (!center) {
201+
// Center is taken as the first image whose rotation is present in the
202+
// problem variables.
199203
center = image_id;
200-
counter++;
201204
}
205+
202206
if (!options_.optimize_rotations)
203207
problem_->SetParameterBlockConstant(
204208
image.cam_from_world.rotation.coeffs().data());
@@ -208,11 +212,16 @@ void BundleAdjuster::ParameterizeVariables(
208212
}
209213
}
210214

215+
if (!center.has_value()) {
216+
LOG(ERROR) << "No valid image found in the problem parameters.";
217+
return false;
218+
}
219+
211220
// Set the first camera to be fixed to remove the gauge ambiguity.
212221
problem_->SetParameterBlockConstant(
213-
images[center].cam_from_world.rotation.coeffs().data());
222+
images[*center].cam_from_world.rotation.coeffs().data());
214223
problem_->SetParameterBlockConstant(
215-
images[center].cam_from_world.translation.data());
224+
images[*center].cam_from_world.translation.data());
216225

217226
// Parameterize the camera parameters, or set them to be constant if desired
218227
if (options_.optimize_intrinsics && !options_.optimize_principal_point) {
@@ -244,6 +253,7 @@ void BundleAdjuster::ParameterizeVariables(
244253
}
245254
}
246255
}
256+
return true;
247257
}
248258

249259
} // namespace glomap

glomap/estimators/bundle_adjustment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BundleAdjuster {
6666
std::unordered_map<track_t, Track>& tracks);
6767

6868
// Parameterize the variables, set some variables to be constant if desired
69-
void ParameterizeVariables(std::unordered_map<camera_t, Camera>& cameras,
69+
bool ParameterizeVariables(std::unordered_map<camera_t, Camera>& cameras,
7070
std::unordered_map<image_t, Image>& images,
7171
std::unordered_map<track_t, Track>& tracks);
7272

0 commit comments

Comments
 (0)