42 #include <glog/logging.h>
44 #include "../util/types.h"
48 using Eigen::MatrixXd;
53 const std::vector<Camera>& cameras,
Point3D& point) {
54 if (features.size() != cameras.size()) {
56 <<
"Number of features does not match number of cameras.";
60 if (features.size() < 2) {
61 LOG(WARNING) <<
"Need at least two features and cameras to triangulate.";
67 A.resize(features.size() * 2, 4);
68 for (
size_t ii = 0; ii < features.size(); ++ii) {
69 double u = features[ii].u_;
70 double v = features[ii].v_;
73 A.row(2*ii+0) = u * P.row(2) - P.row(0);
74 A.row(2*ii+1) = v * P.row(2) - P.row(1);
78 Eigen::JacobiSVD<MatrixXd> svd;
79 svd.compute(A, Eigen::ComputeThinU | Eigen::ComputeFullV);
80 if (!svd.computeV()) {
81 VLOG(1) <<
"Failed to compute a singular value decomposition of A matrix.";
86 point =
Point3D(svd.matrixV().block(0, 3, 3, 1) / svd.matrixV()(3,3));
89 for (
size_t ii = 0; ii < cameras.size(); ++ii) {
90 double u = 0.0, v = 0.0;
91 if (!cameras[ii].WorldToImage(point.
X(), point.
Y(), point.
Z(), &u, &v)) {
104 features.push_back(feature_match.
feature1_);
105 features.push_back(feature_match.
feature2_);
107 std::vector<Camera> cameras;
108 cameras.push_back(camera1);
109 cameras.push_back(camera2);
122 bool triangulated_all_points =
true;
123 for (
size_t ii = 0; ii < feature_matches.size(); ++ii) {
127 if (!
Triangulate(feature_matches[ii], camera1, camera2, point)) {
128 triangulated_all_points =
false;
131 points.push_back(point);
134 return triangulated_all_points;
std::vector< Point3D > Point3DList
std::vector< Feature > FeatureList
::Eigen::Matrix< double, 3, 4 > Matrix34d
std::vector< FeatureMatch > FeatureMatchList
bool Triangulate(const FeatureList &features, const std::vector< Camera > &cameras, Point3D &point)