Skip to content

Commit f2acb9c

Browse files
committed
fix the bug that relative pose estimation fails when camera model is not supported by poselib
1 parent 18a70ee commit f2acb9c

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

glomap/estimators/relpose_estimation.cc

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,53 @@ void EstimateRelativePoses(ViewGraph& view_graph,
4444
const Image& image2 = images[image_pair.image_id2];
4545
const Eigen::MatrixXi& matches = image_pair.matches;
4646

47+
const Camera& camera1 = cameras[image1.camera_id];
48+
const Camera& camera2 = cameras[image2.camera_id];
49+
poselib::Camera camera_poselib1 = ColmapCameraToPoseLibCamera(camera1);
50+
poselib::Camera camera_poselib2 = ColmapCameraToPoseLibCamera(camera2);
51+
bool valid_camera_model =
52+
(camera_poselib1.model_id >= 0 && camera_poselib2.model_id >= 0);
53+
4754
// Collect the original 2D points
4855
points2D_1.clear();
4956
points2D_2.clear();
5057
for (size_t idx = 0; idx < matches.rows(); idx++) {
5158
points2D_1.push_back(image1.features[matches(idx, 0)]);
5259
points2D_2.push_back(image2.features[matches(idx, 1)]);
5360
}
54-
61+
// If the camera model is not supported by poselib
62+
if (!valid_camera_model) {
63+
// Undistort points
64+
// Note that here, we still rescale by the focal length (to avoid
65+
// change the RANSAC threshold)
66+
for (size_t idx = 0; idx < matches.rows(); idx++) {
67+
points2D_1[idx] =
68+
camera1.Focal() * camera1.CamFromImg(points2D_1[idx]);
69+
points2D_2[idx] =
70+
camera2.Focal() * camera2.CamFromImg(points2D_2[idx]);
71+
}
72+
// Reset the camera to be the pinhole camera with original focal
73+
// length and zero principal point
74+
camera_poselib1 = poselib::Camera("SIMPLE_PINHOLE",
75+
{camera1.Focal(), 0., 0.},
76+
camera1.width,
77+
camera1.height);
78+
camera_poselib2 = poselib::Camera("SIMPLE_PINHOLE",
79+
{camera2.Focal(), 0., 0.},
80+
camera2.width,
81+
camera2.height);
82+
}
5583
inliers.clear();
5684
poselib::CameraPose pose_rel_calc;
5785
try {
58-
poselib::estimate_relative_pose(
59-
points2D_1,
60-
points2D_2,
61-
ColmapCameraToPoseLibCamera(cameras[image1.camera_id]),
62-
ColmapCameraToPoseLibCamera(cameras[image2.camera_id]),
63-
options.ransac_options,
64-
options.bundle_options,
65-
&pose_rel_calc,
66-
&inliers);
86+
poselib::estimate_relative_pose(points2D_1,
87+
points2D_2,
88+
camera_poselib1,
89+
camera_poselib2,
90+
options.ransac_options,
91+
options.bundle_options,
92+
&pose_rel_calc,
93+
&inliers);
6794
} catch (const std::exception& e) {
6895
LOG(ERROR) << "Error in relative pose estimation: " << e.what();
6996
image_pair.is_valid = false;

0 commit comments

Comments
 (0)