50 #include <gflags/gflags.h>
51 #include <glog/logging.h>
56 #include "../camera/camera.h"
59 "Fraction of keypoint matches whose triangulation must be "
60 "visible from both cameras. This value should be lowered if you "
61 "expect lots of noisy matches.");
70 Matrix3d K1(intrinsics1.
K());
71 Matrix3d K2(intrinsics2.
K());
74 return K2.transpose() * F * K1;
84 Pose& relative_pose) {
92 Eigen::JacobiSVD<Matrix3d> svd;
93 svd.compute(E, Eigen::ComputeFullU | Eigen::ComputeFullV);
94 if (!svd.computeU() || !svd.computeV()) {
95 VLOG(1) <<
"Failed to compute a singular value decomposition of "
96 <<
"the essential matrix.";
102 Matrix3d sigma(Matrix3d::Identity());
104 Matrix3d E_augmented = svd.matrixU() * sigma * svd.matrixV().transpose();
106 svd.compute(E_augmented, Eigen::ComputeFullU | Eigen::ComputeFullV);
107 if (!svd.computeU() || !svd.computeV()) {
108 VLOG(1) <<
"Failed to compute a singular value decomposition of "
109 <<
"the essential matrix.";
114 Matrix3d R1 = svd.matrixU() * W * svd.matrixV().transpose();
115 Matrix3d R2 = svd.matrixU() * W.transpose() * svd.matrixV().transpose();
118 if (R1.determinant() < 0)
120 if (R2.determinant() < 0)
125 t1 = svd.matrixU().col(2);
129 std::vector<Pose> poses;
130 poses.push_back(
Pose(R1, t1));
131 poses.push_back(
Pose(R1, t2));
132 poses.push_back(
Pose(R2, t1));
133 poses.push_back(
Pose(R2, t2));
145 int best_num_points = -1;
147 double u = 0.0, v = 0.0;
148 for (
int ii = 0; ii < poses.size(); ii++) {
158 for (
int jj = 0; jj < matches.size(); jj++) {
162 if (!
Triangulate(matches[jj], camera1, camera2, point)) {
170 if (num_points > best_num_points) {
171 best_num_points = num_points;
172 best_pose = poses[ii];
177 if (best_num_points < FLAGS_min_points_visible_ratio * matches.size()) {
178 VLOG(1) <<
"Did not find enough points in front of both cameras.";
182 relative_pose = best_pose;
void SetIntrinsics(const CameraIntrinsics &)
DEFINE_double(min_points_visible_ratio, 0.8,"Fraction of keypoint matches whose triangulation must be ""visible from both cameras. This value should be lowered if you ""expect lots of noisy matches.")
bool ComputeExtrinsics(const Matrix3d &E, const FeatureMatchList &matches, const CameraIntrinsics &intrinsics1, const CameraIntrinsics &intrinsics2, Pose &relative_pose)
void SetExtrinsics(const CameraExtrinsics &)
void SetWorldToCamera(const Pose &world_to_camera)
Matrix3d ComputeEssentialMatrix(const Matrix3d &F, const CameraIntrinsics &intrinsics1, const CameraIntrinsics &intrinsics2)
std::vector< FeatureMatch > FeatureMatchList
bool Triangulate(const FeatureList &features, const std::vector< Camera > &cameras, Point3D &point)