MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
fundamental.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 *
9 * The relation between two cameras is defined by the fundamental matrix.
10 * In the calibrated case, where the camera internal parameters (focal
11 * length, principal point) are known, pose can be described with the essential
12 * matrix.
13 *
14 * The fundamental matrix can be computed from eight point correspondences
15 * in the images, using the 8-point algorithm. It is also possible to compute
16 * the fundamental matrix from seven point correspondences by enforcing
17 * further constraints -- the 7-point algorithm.
18 * If the camera calibration is know, the essential matrix can be computed
19 * from as few as five point correspondences -- the 5-point algorithm.
20 *
21 * The input points to the N-point algorithms should be normalized such that
22 * the mean of the points is zero and the points fit in the unit square. This
23 * makes solving for the fundamental matrix numerically stable. The inverse
24 * transformation can then applied afterwards. That is, for transformations
25 * T1 and T2, the de-normalized fundamental matrix is given by F' = T2* F T1,
26 * where T* is the transpose of T.
27 *
28 * Camera matrix can be extracted from the essential matrix as described
29 * in [Sect 9.6.2, Hartley, Zisserman, 2004].
30 *
31 * Properties of the Fundamental matrix F:
32 * - Rank 2 homogenous matrix with 7 degrees of freedom, det(F) = 0.
33 * - Relates images points x, x' in two cameras: x'^T F x = 0.
34 * - If F is the fundamental matrix for camera pair (P,P'), the transpose
35 * F^T is the fundamental matrix for camera pair (P',P).
36 * - Two non-zero singular values.
37 *
38 * Properties of the Essential matrix E:
39 * - Rank 2 homogenous matrix with 5 degrees of freedom, det(E) = 0.
40 * - Relation to Fundamental matrix: E = K'^T F K.
41 * - Relates normalized image points x, x' in two cameras: x'^T E x = 0.
42 * Normalized image point x := K^-1 x* with x* (unnormalized) image point.
43 * - Two equal singular vales, the third one is zero.
44 */
45#ifndef SFM_FUNDAMENTAL_HEADER
46#define SFM_FUNDAMENTAL_HEADER
47
48#include <limits>
49#include <vector>
50
51#include "math/vector.h"
52#include "math/matrix.h"
53#include "sfm/defines.h"
54#include "sfm/camera_pose.h"
55#include "sfm/correspondence.h"
56
58
62
72bool
74 FundamentalMatrix* result);
75
88bool
89fundamental_8_point (Eight2DPoints const& points_view_1,
90 Eight2DPoints const& points_view_2, FundamentalMatrix* result);
91
96void
98
103void
105
119void
121 std::vector<CameraPose>* result);
122
128void
129fundamental_from_pose (CameraPose const& cam1, CameraPose const& cam2,
130 FundamentalMatrix* result);
131
136double
137sampson_distance (FundamentalMatrix const& fundamental,
138 Correspondence2D2D const& match);
139
146template <typename T, int DIM>
147void
149 math::Matrix<T, 3, 3>* transformation);
150
151/* ---------------------------------------------------------------- */
152
153#if 0 // This is not yet implemented!
154typedef math::Matrix<double, 3, 7> Seven2DPoints;
155typedef math::Matrix<double, 3, 5> Five2DPoints;
156
162bool
163pose_7_point (Seven2DPoints const& points_view_1,
164 Seven2DPoints const& points_view_2,
165 std::vector<FundamentalMatrix>* result);
166
176bool
177pose_5_point (Five2DPoints const& points_view_1,
178 Five2DPoints const& points_view_2,
179 std::vector<EssentialMatrix>* result);
180#endif
181
182/* ---------------------------------------------------------------- */
183
184template <typename T, int DIM>
185void
187 math::Matrix<T, 3, 3>* transformation)
188{
189 math::Vector<T, 3> mean(T(0));
190 math::Vector<T, 3> aabb_min(std::numeric_limits<T>::max());
191 math::Vector<T, 3> aabb_max(-std::numeric_limits<T>::max());
192 for (int i = 0; i < DIM; ++i)
193 {
194 for (int j = 0; j < 3; ++j)
195 {
196 mean[j] += points(j, i);
197 aabb_min[j] = std::min(aabb_min[j], points(j, i));
198 aabb_max[j] = std::max(aabb_max[j], points(j, i));
199 }
200 }
201 mean /= static_cast<T>(DIM);
202 T norm = (aabb_max - aabb_min).maximum();
203 math::Matrix<T, 3, 3>& t = *transformation;
204 t[0] = T(1) / norm; t[1] = T(0); t[2] = -mean[0] / norm;
205 t[3] = T(0); t[4] = T(1) / norm; t[5] = -mean[1] / norm;
206 t[6] = T(0); t[7] = T(0); t[8] = T(1);
207}
208
210
211#endif // SFM_FUNDAMENTAL_HEADER
Matrix class for arbitrary dimensions and types.
Definition matrix.h:54
Vector class for arbitrary dimensions and types.
Definition vector.h:87
void enforce_fundamental_constraints(FundamentalMatrix *matrix)
Constraints the given matrix to have TWO NON-ZERO eigenvalues.
bool fundamental_least_squares(Correspondences2D2D const &points, FundamentalMatrix *result)
Algorithm to compute the fundamental or essential matrix from image correspondences.
void compute_normalization(math::Matrix< T, 3, DIM > const &points, math::Matrix< T, 3, 3 > *transformation)
Computes a transformation for 2D points in homogeneous coordinates such that the mean of the points i...
void enforce_essential_constraints(EssentialMatrix *matrix)
Constraints the given matrix to have TWO EQUAL NON-ZERO eigenvalues.
std::vector< Correspondence2D2D > Correspondences2D2D
void fundamental_from_pose(CameraPose const &cam1, CameraPose const &cam2, FundamentalMatrix *result)
Computes the fundamental matrix corresponding to cam1 and cam2.
void pose_from_essential(EssentialMatrix const &matrix, std::vector< CameraPose > *result)
Retrieves the camera matrices from the essential matrix.
bool fundamental_8_point(Eight2DPoints const &points_view_1, Eight2DPoints const &points_view_2, FundamentalMatrix *result)
Algorithm to compute the fundamental or essential matrix from 8 image correspondences.
double sampson_distance(FundamentalMatrix const &F, Correspondence2D2D const &m)
Computes the Sampson distance for an image correspondence given the fundamental matrix between two vi...
#define SFM_NAMESPACE_END
Definition defines.h:14
#define SFM_NAMESPACE_BEGIN
Definition defines.h:13
The camera pose is the 3x4 matrix P = K [R | t].
Definition camera_pose.h:40
Two image coordinates which correspond to each other in terms of observing the same point in the scen...