@@ -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
192192void 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
227245void 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 ())) {
0 commit comments