Skip to content

Commit 09a4d3a

Browse files
committed
fix the bug for ba with rig calibration
1 parent 8100d69 commit 09a4d3a

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

glomap/estimators/bundle_adjustment.cc

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ bool BundleAdjuster::Solve(std::unordered_map<rig_t, Rig>& rigs,
3131

3232
// Add the cameras and points to the parameter groups for schur-based
3333
// optimization
34-
AddCamerasAndPointsToParameterGroups(cameras, frames, tracks);
34+
AddCamerasAndPointsToParameterGroups(rigs, cameras, frames, tracks);
3535

3636
// Parameterize the variables
37-
ParameterizeVariables(cameras, frames, tracks);
37+
ParameterizeVariables(rigs, cameras, frames, tracks);
3838

3939
// Set the solver options.
4040
ceres::Solver::Summary summary;
@@ -190,6 +190,7 @@ void BundleAdjuster::AddPointToCameraConstraints(
190190
}
191191

192192
void BundleAdjuster::AddCamerasAndPointsToParameterGroups(
193+
std::unordered_map<rig_t, Rig>& rigs,
193194
std::unordered_map<camera_t, Camera>& cameras,
194195
std::unordered_map<frame_t, Frame>& frames,
195196
std::unordered_map<track_t, Track>& tracks) {
@@ -217,6 +218,23 @@ void BundleAdjuster::AddCamerasAndPointsToParameterGroups(
217218
}
218219
}
219220

221+
// Add the cam_from_rigs to be estimated into the parameter group
222+
for (auto& [rig_id, rig] : rigs) {
223+
for (const auto& [sensor_id, sensor] : rig.Sensors()) {
224+
if (rig.IsRefSensor(sensor_id)) continue;
225+
if (sensor_id.type == SensorType::CAMERA) {
226+
Eigen::Vector3d& translation = rig.SensorFromRig(sensor_id).translation;
227+
if (problem_->HasParameterBlock(translation.data())) {
228+
parameter_ordering->AddElementToGroup(translation.data(), 1);
229+
}
230+
Eigen::Quaterniond& rotation = rig.SensorFromRig(sensor_id).rotation;
231+
if (problem_->HasParameterBlock(rotation.coeffs().data())) {
232+
parameter_ordering->AddElementToGroup(rotation.coeffs().data(), 1);
233+
}
234+
}
235+
}
236+
}
237+
220238
// Add camera parameters to group 1.
221239
for (auto& [camera_id, camera] : cameras) {
222240
if (problem_->HasParameterBlock(camera.params.data()))
@@ -225,6 +243,7 @@ void BundleAdjuster::AddCamerasAndPointsToParameterGroups(
225243
}
226244

227245
void BundleAdjuster::ParameterizeVariables(
246+
std::unordered_map<rig_t, Rig>& rigs,
228247
std::unordered_map<camera_t, Camera>& cameras,
229248
std::unordered_map<frame_t, Frame>& frames,
230249
std::unordered_map<track_t, Track>& tracks) {
@@ -274,6 +293,22 @@ void BundleAdjuster::ParameterizeVariables(
274293
}
275294
}
276295

296+
// If we optimize the rig poses, then parameterize them
297+
if (options_.optimize_rig_poses) {
298+
for (auto& [rig_id, rig] : rigs) {
299+
for (const auto& [sensor_id, sensor] : rig.Sensors()) {
300+
if (rig.IsRefSensor(sensor_id)) continue;
301+
if (sensor_id.type == SensorType::CAMERA) {
302+
Eigen::Quaterniond& rotation = rig.SensorFromRig(sensor_id).rotation;
303+
if (problem_->HasParameterBlock(rotation.coeffs().data())) {
304+
colmap::SetQuaternionManifold(
305+
problem_.get(), rotation.coeffs().data());
306+
}
307+
}
308+
}
309+
}
310+
}
311+
277312
if (!options_.optimize_points) {
278313
for (auto& [track_id, track] : tracks) {
279314
if (problem_->HasParameterBlock(track.xyz.data())) {

glomap/estimators/bundle_adjustment.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,17 @@ class BundleAdjuster {
6464

6565
// Set the parameter groups
6666
void AddCamerasAndPointsToParameterGroups(
67+
std::unordered_map<rig_t, Rig>& rigs,
6768
std::unordered_map<camera_t, Camera>& cameras,
6869
std::unordered_map<frame_t, Frame>& frames,
6970
std::unordered_map<track_t, Track>& tracks);
7071

7172
// Parameterize the variables, set some variables to be constant if desired
72-
void ParameterizeVariables(std::unordered_map<camera_t, Camera>& cameras,
73-
std::unordered_map<frame_t, Frame>& frames,
74-
std::unordered_map<track_t, Track>& tracks);
73+
void ParameterizeVariables(
74+
std::unordered_map<rig_t, Rig>& rigs,
75+
std::unordered_map<camera_t, Camera>& cameras,
76+
std::unordered_map<frame_t, Frame>& frames,
77+
std::unordered_map<track_t, Track>& tracks);
7578

7679
BundleAdjusterOptions options_;
7780

0 commit comments

Comments
 (0)