1/** \page page_how_to_use How to use
2 *
3 * This page gives an introduction to the usage of OpenGV including a description of the interface and explicit examples. More information can be found in [17]. However, in order to have a smooth communication and full understanding of the functionality and documentation of the library, we first need to clearly define the meaning of a couple of words in the present context.
4 *
5 * \section sec_vocabulary Vocabulary
6 *
7 * <ul>
8 * <li> <b>Bearing vector</b>: A bearing vector is defined to be a 3-vector with unit norm bearing at a spatial 3D point from a camera reference frame. It has 2 degrees of freedom, which are the azimuth and elevation in the camera reference frame. Because it has only two degrees of freedom, we frequently refer to it as a 2D information. It is normally expressed in a camera reference frame.
9 * <li> <b>Landmark</b>: A landmark describes a 3D spatial point (usually expressed in a fixed frame called world reference frame).
10 * <li> <b>Camera</b>: OpenGV assumes to be in the calibrated case, and landmark measurements are always given in form of bearing vectors in a camera frame. A camera therefore denotes a camera reference frame with a set of bearing vectors, all pointing from the origin to landmarks. The following figure shows a camera c with bearing vectors (in red). The bearing vectors are all lying on the unit-sphere centered around the camera.
11 *
12 * \image html central.png
13 * \image latex central.pdf "" width=0.45\columnwidth
14 *
15 * <li> <b>Viewpoint</b>: You will notice that the documentation of the code very frequently talks about viewpoints instead of cameras. One of the advantages of OpenGV is that it can transparently handle both the central and the non-central case. The viewpoint is a generalization of a camera, and can contain an arbitrary number of cameras each one having it's own landmark-measurements (e.g. bearing vectors). A practical example of a viewpoint would be the set of images and related measurements captured by a fully-calibrated, rigid multi-camera rig with synchronized cameras, which therefore still represents a single (multi)-snapshot (i.e. viewpoint). Each camera has its own transformation to the viewpoint frame. In the central case the viewpoint simply contains a single camera with an identity transformation. The most general case-the generalized camera-can also be described by the viewpoint. Each bearing vector would then have it's own camera and related transformation. A generalized camera would hence be represented by an exhaustive multi-camera system. The following image shows a viewpoint vp (in blue) with three cameras c, c', and c'', each one containing its own bearing vector measurements.
16 *
17 * \image html noncentral.png
18 * \image latex noncentral.pdf "" width=0.8\columnwidth
19 *
20 * <li> <b>Pose</b>: By a pose, we understand here the position and orientation of a viewpoint, either with respect to a fixed spatial reference frame called the "world" reference frame, or with respect to another viewpoint.
21 * <li> <b>Absolute Pose</b>: By absolute pose, we understand the pose of a viewpoint in the world reference frame.
22 * <li> <b>Relative Pose</b>: By relative pose, we understand the pose of a viewpoint with respect to another viewpoint.
23 * <li> <b>Correspondence</b>: By a correspondence, we understand a pair of bearing-vectors pointing at the same landmark from different viewpoints (2D-2D correspondence), a bearing vector and a world-point it is pointing at (2D-3D correspondence), or a pair of expressions of the same landmark in different frames (3D-3D correspondence).
24 * </ul>
25 *
26 * \section sec_organization Organization of the library
27 *
28 * The library-structure is best analyzed at the hand of the namespace or directory hierarchy (as a matter of fact, there is no difference between the two):
29 * <ul>
30 * <li> opengv: contains generic things such as the types used throughout the library.
31 * <li> opengv/math: contains a bunch of math functions that are used in different algorithms, mainly for root-finding and rotation-related stuff.
32 * <li> opengv/absolute_pose: contains the absolute-pose methods. methods.hpp is the main-header that contains the method-declarations. You can also find a bunch of adapters here for interfacing with the algorithms (explained in the next section). The sub-folder modules contains declarations of internal methods.
33 * <li> opengv/relative_pose: contains the relative-pose methods. methods.hpp is the main-header that contains the method-declarations. You can also find a bunch of adapters here for interfacing with the algorithms (explained in the next section). The sub-folder modules contains declarations of internal methods.
34 * <li> opengv/point_cloud: contains the point-cloud alignment methods. Again, methods.hpp contains the declarations, and the folder contains adapters for interfacing (explained below).
35 * <li> opengv/triangulation: contains the triangulation methods.
36 * <li> opengv/sac: contains base-classes for sample-consensus methods and problems. So far, only the Ransac algorithm is implemented.
37 * <li> opengv/sac_problems: contains sample-consensus problems derived from the base-class. Implements sample-consensus problems for point-cloud alignment and central as well as non-central absolute and relative-pose estimation.
38 * </ul>
39 *
40 * \section sec_interface Interface
41 *
42 * You will quickly notice that all methods in OpenGV use a variable called adapter as a function-call parameter. OpenGV is designed based on the adapter pattern. "Adapters" in OpenGV are used as "visitors" to all geometric vision methods. They contain the landmarks, bearing-vectors, poses, correspondences etc. used as an input to the different methods (or references to the alike), and allow to access those elements with a unified interface. Adapters are derived from a base-class that defines the unified interface and they have to implement the related functions for accessing bearing-vectors, world-points, camera-transformations, viewpoint-poses, etc. There are three adapter-base-classes:
43 *
44 * <ul>
45 * <li> <b>AbsoluteAdapterBase</b>: Base-class for adapters holding 2D-3D correspondences for absolute-pose methods.
46 * <li> <b>RelativeAdapterBase</b>: Base-class for adapters holding 2D-2D correspondences for relative-pose methods.
47 * <li> <b>PointCloudAdapterBase</b>: Base-class for adapters holding 3D-3D correspondences for point-cloud alignment methods.
48 * </ul>
49 *
50 * The derived adapters have the task of transforming the data from the user-format to OpenGV types. This gives the library great flexibility. Users have to implement only a couple of adapters for the specific data-format they are using, and can then access the full functionality of the library. OpenGV currently contains adapters that simply hold references to OpenGV types (no transformation needed) plus adapters for mexArrays used within the Matlab-interface. Further adapters are planned, such as for instance an adapter for OpenCV keypoint and match-types including a camera model. The user would then be able to chose whether normalization of keypoints is done "on-demand" or "once for all" at the beginning, which is more efficient in sample-consensus problems.
51 *
52 * Note that adapters containing the tag "Central" in their name are adapters for a single camera (i.e. view-points with only one camera having identity transformation). Adapters having the tag "Noncentral" in their name are meant for view-points with multiple cameras (e.g., multi-camera systems, generalized cameras).
53 *
54 * Please check out the doxygen documentation on the above base-classes, they contain important documentation on the functions that need to be overloaded for a proper implementation of an adapter.
55 *
56 * \section sec_conventions Conventions, problem types, and examples
57 *
58 * As already mentioned, the entire library is assuming calibrated cameras/viewpoints, and it operates with 3D unit bearing vectors expressed in the camera frame. Calibrated means that the configuration of the multi-camera system (i.e. the inter-camera transformations) is known. The following introduces the different problems that can be solved with the library, and outlines the conventions for transformations (translations and rotations) in their context. <b>Note that all problems have solutions for both the minimal and non-minimal cases, and may also be solved as sample-consensus or non-linear optimization problems</b>. The code samples are mostly taken from the test files, which you can compile along with the library by setting BUILD_TESTS in CMakeLists.txt to ON.
59 *
60 * <ul>
61 *
62 * <li> <b>Central absolute pose:</b> The central absolute pose problem consists of finding the pose of a camera (e.g. viewpoint with a single camera) given a number of 2D-3D correspondences between bearing vectors in the camera frame and points in the world frame. The seeked transformation is given by the position \f$ \mathbf{t}_{c} \f$ of the camera seen from the world frame and the rotation \f$ \mathbf{R}_{c} \f$ from the camera to the world frame. This is what the algorithms return (or part of it), and what the adapters can hold as known or prior information.
63 *
64 * \image html absolute_central.png
65 * \image latex absolute_central.pdf "" width=0.8\columnwidth
66 *
67 * The minimal variants are p2p (a solution for position if rotation is known), p3p_kneip [1], p3p_gao [2], and UPnP [19]. The non-minimal variants are epnp [4], and UPnP [19]. The non-linear optimization variant is called optimize_nonlinear. Here's how to use them:
68 *
69\code
70// create the central adapter
71absolute_pose::CentralAbsoluteAdapter adapter(
72    bearingVectors, points );
73
74// Kneip's P2P (uses rotation from adapter)
75adapter.setR( knownRotation );
76translation_t p2p_translation =
77    absolute_pose::p2p( adapter, indices1 );
78
79// Kneip's P3P
80transformations_t p3p_kneip_transformations =
81    absolute_pose::p3p_kneip( adapter, indices2 );
82
83// Gao's P3P
84transformations_t p3p_gao_transformations =
85    absolute_pose::p3p_gao( adapter, indices2 );
86
87// Lepetit's Epnp (using all correspondences)
88transformation_t epnp_transformation =
89    absolute_pose::epnp(adapter);
90
91// UPnP (using all correspondences)
92transformations_t upnp_transformations =
93    absolute_pose::upnp(adapter);
94
95// UPnP (using three correspondences)
96transformations_t upnp_transformations =
97    absolute_pose::upnp( adapter, indices2 );
98
99// non-linear optimization (using all correspondences)
100adapter.sett(initial_translation);
101adapter.setR(initial_rotation);
102transformation_t nonlinear_transformation =
103    absolute_pose::optimize_nonlinear(adapter);
104
105\endcode
106 *
107 * p3p_kneip, p3p_gao, and epnp can also be used within a sample consensus context. The following shows how to do it:
108 *
109\code
110// create the central adapter
111absolute_pose::CentralAbsoluteAdapter adapter(
112    bearingVectors, points );
113
114// create a Ransac object
115sac::Ransac<sac_problems::absolute_pose::AbsolutePoseSacProblem> ransac;
116
117// create an AbsolutePoseSacProblem
118// (algorithm is selectable: KNEIP, GAO, or EPNP)
119std::shared_ptr<sac_problems::absolute_pose::AbsolutePoseSacProblem>
120    absposeproblem_ptr(
121    new sac_problems::absolute_pose::AbsolutePoseSacProblem(
122    adapter, sac_problems::absolute_pose::AbsolutePoseSacProblem::KNEIP ) );
123
124// run ransac
125ransac.sac_model_ = absposeproblem_ptr;
126ransac.threshold_ = threshold;
127ransac.max_iterations_ = maxIterations;
128ransac.computeModel();
129
130// get the result
131transformation_t best_transformation =
132    ransac.model_coefficients_;
133\endcode
134 *
135 * These examples are taken from test_absolute_pose.cpp and test_absolute_pose_sac.cpp.
136 *
137 * <li> <b>Non-central absolute pose:</b> The non-central absolute pose problem consists of finding the pose of a viewpoint given a number of 2D-3D correspondences between bearing vectors in multiple camera frames and points in the world frame. The seeked transformation is given by the position \f$ \mathbf{t}_{vp} \f$ of the viewpoint seen from the world frame and the rotation \f$ \mathbf{R}_{vp} \f$ from the viewpoint to the world frame. This is what the algorithms return, and what the adapters can hold as known or prior information.
138 *
139 * \image html absolute_noncentral.png
140 * \image latex absolute_noncentral.pdf "" width=0.8\columnwidth
141 *
142 * The minimal variant is gp3p, and the non-minimal variant is gpnp [3]. UPnP can be used for both the minimal and the non-minimal case [19]. The non-linear optimization variant is still optimize_nonlinear (it handles both cases). Here's how to use them:
143 *
144\code
145// create the non-central adapter
146absolute_pose::NoncentralAbsoluteAdapter adapter(
147    bearingVectors,
148    camCorrespondences,
149    points,
150    camOffsets,
151    camRotations );
152
153// Kneip's GP3P
154transformations_t gp3p_transformations =
155    absolute_pose::gp3p( adapter, indices1 );
156
157// Kneip's GPNP (using all correspondences)
158transformation_t gpnp_transformation =
159    absolute_pose::gpnp(adapter);
160
161// UPnP (using all correspondences)
162transformations_t upnp_transformations =
163    absolute_pose::upnp( adapter );
164
165// UPnP (using only 3 correspondences)
166transformations_t upnp_transformations_3 =
167    absolute_pose::upnp( adapter, indices1 );
168
169// non-linear optimization
170adapter.sett(initial_translation);
171adapter.setR(initial_rotation);
172transformation_t nonlinear_transformation =
173    absolute_pose::optimize_nonlinear(adapter);
174\endcode
175 *
176 * gp3p can also be used within a sample-consensus context. It remains an AbsolutePoseSacProblem, this one is usable for both the central and the non-central case. We simply have to set algorithm to GP3P:
177 *
178\code
179// create the non-central adapter
180absolute_pose::NoncentralAbsoluteAdapter adapter(
181    bearingVectors,
182    camCorrespondences,
183    points,
184    camOffsets,
185    camRotations );
186
187// create a RANSAC object
188sac::Ransac<sac_problems::absolute_pose::AbsolutePoseSacProblem> ransac;
189
190// create a absolute-pose sample consensus problem (using GP3P as an algorithm)
191std::shared_ptr<sac_problems::absolute_pose::AbsolutePoseSacProblem>
192    absposeproblem_ptr(
193    new sac_problems::absolute_pose::AbsolutePoseSacProblem(
194    adapter, sac_problems::absolute_pose::AbsolutePoseSacProblem::GP3P ) );
195
196// run ransac
197ransac.sac_model_ = absposeproblem_ptr;
198ransac.threshold_ = threshold;
199ransac.max_iterations_ = maxIterations;
200ransac.computeModel();
201
202// get the result
203transformation_t best_transformation =
204    ransac.model_coefficients_;
205\endcode
206 *
207 * These examples are taken from test_noncentral_absolute_pose.cpp and test_noncentral_absolute_pose_sac.cpp.
208 *
209 * <li> <b>Central relative pose:</b> The central relative pose problem consists of finding the pose of a camera (e.g. viewpoint with a single camera) with respect to a different camera given a number of 2D-2D correspondences between bearing vectors in the camera frames. The seeked transformation is given by the position \f$ \mathbf{t}_{c'}^{c} \f$ of the second camera seen from the first one and the rotation \f$ \mathbf{R}_{c'}^{c} \f$ from the second camera back to the first camera frame. This is what the algorithms return (or part of it), and what the adapters can hold as known or prior information.
210 *
211 * \image html relative_central.png
212 * \image latex relative_central.pdf "" width=0.6\columnwidth
213 *
214 * There are many central relative-pose algorithms in the library. The minimal variants are twopt (in case the rotation is known), twopt_rotationOnly (in case there is only rotational change, and using only two points), fivept_stewenius [5], fivept_nister [6], and fivept_kneip [7]. The libary also contains non-minimal variants, namely rotationOnly (in case of pure-rotation change), sevenpt [8], eightpt [9,10] and the new eigensolver [11] methods. All of them except twopt, twopt_rotationOnly, and fivept_kneip can be used for an arbitrary number of correspondences (of course at least the minimal number). The non-linear optimization variant is again called optimize_nonlinear. Here's how to use most of them (we assume a regular situation here, and thus omit the rotationOnly algorithms):
215 *
216\code
217// create the central relative adapter
218relative_pose::CentralRelativeAdapter adapter(
219    bearingVectors1, bearingVectors2 );
220
221// Relative translation with only two point-correspondences
222// (no or known rotation)
223adapter.setR(knownRotation);
224translation_t twopt_translation =
225    relative_pose::twopt( adapter, true, indices1 );
226
227// Stewenius' 5-point algorithm
228complexEssentials_t fivept_stewenius_essentials =
229    relative_pose::fivept_stewenius( adapter, indices2 );
230
231// Nister's 5-point algorithm
232essentials_t fivept_nister_essentials =
233    relative_pose::fivept_nister( adapter, indices2 );
234
235// Kneip's 5-point algorithm
236rotations_t fivept_kneip_rotations =
237    relative_pose::fivept_kneip( adapter, indices2 );
238
239// the 7-point algorithm
240essentials_t sevenpt_essentials =
241    relative_pose::sevenpt( adapter, indices3 );
242
243// the 8-point algorithm
244essential_t eightpt_essential =
245    relative_pose::eightpt( adapter, indices4 );
246
247// Kneip's eigensolver
248adapter.setR(initial_rotation);
249eigensolver_rotation =
250    relative_pose::eigensolver( adapter, indices5 );
251
252// non-linear optimization (using all available correspondences)
253adapter.sett(initial_translation);
254adapter.setR(initial_rotation);
255transformation_t nonlinear_transformation =
256    relative_pose::optimize_nonlinear(adapter);
257\endcode
258 *
259 * fivept_nister, fivept_stewenius, sevenpt, and eigthpt can also be used within a random-sample consensus scheme. It is done as follows:
260 *
261\code
262// create the central relative adapter
263relative_pose::CentralRelativeAdapter adapter(
264    bearingVectors1, bearingVectors2 );
265
266// create a RANSAC object
267sac::Ransac<sac_problems::relative_pose::CentralRelativePoseSacProblem> ransac;
268
269// create a CentralRelativePoseSacProblem
270// (set algorithm to STEWENIUS, NISTER, SEVENPT, or EIGHTPT)
271std::shared_ptr<sac_problems::relative_pose::CentralRelativePoseSacProblem>
272    relposeproblem_ptr(
273    new sac_problems::relative_pose::CentralRelativePoseSacProblem(
274    adapter,
275    sac_problems::relative_pose::CentralRelativePoseSacProblem::NISTER ) );
276
277// run ransac
278ransac.sac_model_ = relposeproblem_ptr;
279ransac.threshold_ = threshold;
280ransac.max_iterations_ = maxIterations;
281ransac.computeModel();
282
283// get the result
284transformation_t best_transformation =
285    ransac.model_coefficients_;
286\endcode
287 *
288 * These examples are taken from test_relative_pose.cpp and test_relative_pose_sac.cpp. There are also sample consensus problems for the case of pure-rotation, known rotation, or the eigensolver method. Feel free to explore opengv/sac_problems/relative_pose.
289 *
290 * <li> <b>Non-central relative pose:</b> The non-central relative pose problem consists of finding the pose of a viewpoint with respect to a different viewpoint given a number of 2D-2D correspondences between bearing vectors in multiple camera frames. The seeked transformation is given by the position \f$ \mathbf{t}_{vp'}^{vp} \f$ of the second viewpoint seen from the first one and the rotation \f$ \mathbf{R}_{vp'}^{vp} \f$ from the second viewpoint back to the first viewpoint frame. This is what the algorithms return (or part of it), and what the adapters can hold as known or prior information.
291 *
292 * \image html relative_noncentral.png
293 * \image latex relative_noncentral.pdf "" width=0.8\columnwidth
294 *
295 * There are three non-central relative pose methods in the library, the 17-point algorithm by Li [12], the 6-point method by Stewenius [16], and the new generalized eigensolver [18]. The 17-point algorithm as well as the generalized eigensolver can be used with an arbitrary number of points. The 6-point algorithm is usable with only 6-points exactly. "optimize_nonlinear" is again able to also handle the non-central case. Here's how to use these methods:
296 *
297\code
298// create the non-central relative adapter
299relative_pose::NoncentralRelativeAdapter adapter(
300    bearingVectors1,
301    bearingVectors2,
302    camCorrespondences1,
303    camCorrespondences2,
304    camOffsets,
305    camRotations );
306
307// 6-point algorithm
308rotations_t sixpt_rotations =
309    relative_pose::sixpt( adapter, indices );
310
311// generalized eigensolver (over all points)
312geOutput_t output;
313relative_pose::ge(adapter,output);
314translation_t ge_translation = output.translation.block<3,1>(0,0);
315rotation_t ge_rotation = output.rotation;
316
317// 17-point algorithm
318transformation_t seventeenpt_transformation =
319    relative_pose::seventeenpt( adapter, indices );
320
321// non-linear optimization (using all available correspondences)
322adapter.sett(initial_translation);
323adapter.setR(initial_rotation);
324transformation_t nonlinear_transformation =
325    relative_pose::optimize_nonlinear(adapter);
326\endcode
327 *
328 * All algorithms are also available in a sample-consensus scheme:
329 *
330\code
331// create the non-central relative adapter
332relative_pose::NoncentralRelativeAdapter adapter(
333    bearingVectors1,
334    bearingVectors2,
335    camCorrespondences1,
336    camCorrespondences2,
337    camOffsets,
338    camRotations );
339
340// create a RANSAC object
341sac::Ransac<sac_problems::relative_pose::NoncentralRelativePoseSacProblem>
342    ransac;
343
344// create a NoncentralRelativePoseSacProblem
345std::shared_ptr<
346    sac_problems::relative_pose::NoncentralRelativePoseSacProblem>
347    relposeproblem_ptr(
348    new sac_problems::relative_pose::NoncentralRelativePoseSacProblem(
349    adapter,
350    sac_problems::relative_pose::NoncentralRelativePoseSacProblem::SEVENTEENPT)
351    );
352
353// run ransac
354ransac.sac_model_ = relposeproblem_ptr;
355ransac.threshold_ = threshold;
356ransac.max_iterations_ = maxIterations;
357ransac.computeModel();
358
359// get the result
360transformation_t best_transformation =
361    ransac.model_coefficients_;
362\endcode
363 *
364 * These examples are taken from test_noncentral_relative_pose.cpp and test_noncentral_relative_pose_sac.cpp. Simply set SEVENTEENPT to GE or SIXPT in order to use the alternative algorithms.
365 *
366 * <li> <b>Triangulation of points:</b> OpenGV contains two methods for triangulating points. They are currently only designed for the central case, and compute the position of a point expressed in the first camera given a 2D-2D correspondence between bearing vectors from two cameras. The methods reuse the relative adapter, which need to hold the transformation between the cameras given by the position \f$ \mathbf{t}_{c'}^{c} \f$ of the second camera seen from the first one and the rotation \f$ \mathbf{R}_{c'}^{c} \f$ from the second camera back to the first camera frame.
367 *
368 * \image html triangulation_central.png
369 * \image latex triangulation_central.pdf "" width=0.6\columnwidth
370 *
371 * There are two methods, triangulate (linear) and triangulate2 (a fast non-linear approximation). They are used as follows:
372 *
373\code
374// create a central relative adapter
375// (immediately pass translation and rotation)
376relative_pose::CentralRelativeAdapter adapter(
377    bearingVectors1,
378    bearingVectors2,
379    translation,
380    rotation );
381
382// run method 1
383point_t point =
384    triangulation::triangulate( adapter, index );
385
386//run method 2
387point_t point =
388    triangulation::triangulate2( adapter, index );
389\endcode
390 *
391 * The example is taken from test_triangulation.cpp.
392 *
393 * <li> <b>Alignment of two point-clouds:</b> OpenGV also contains a method for aligning point-clouds. It is currently only designed for the central case, and computes the transformation between two frames given 3D-3D correspondences between points expressed in the two frames (here denoted by c and c', although it ain't necessarily need to be cameras anymore). The method returns the transformation between the frames given by the position \f$ \mathbf{t}_{c'}^{c} \f$ of the second frame seen from the first one and the rotation \f$ \mathbf{R}_{c'}^{c} \f$ from the second frame back to the first frame.
394 *
395 * \image html point_cloud.png
396 * \image latex point_cloud.pdf "" width=0.6\columnwidth
397 *
398 * The method is called threept_arun, and it can be used for an arbitrary number of points (minimum three). There is also a non-linear optimization method again called optimize_nonlinear. The methods are used as follows:
399 *
400\code
401// create the 3D-3D adapter
402point_cloud::PointCloudAdapter adapter(
403    points1, points2 );
404
405// run threept_arun
406transformation_t threept_transformation =
407    point_cloud::threept_arun( adapter, indices );
408
409// run the non-linear optimization over all correspondences
410transformation_t nonlinear_transformation =
411    point_cloud::optimize_nonlinear(adapter);
412\endcode
413 *
414 * There is also a sample-consensus problem for the point-cloud alignment. It is set up as follows:
415 *
416\code
417// create a 3D-3D adapter
418point_cloud::PointCloudAdapter adapter(
419    points1, points2 );
420
421// create a RANSAC object
422sac::Ransac<sac_problems::point_cloud::PointCloudSacProblem> ransac;
423
424// create the sample consensus problem
425std::shared_ptr<sac_problems::point_cloud::PointCloudSacProblem>
426    relposeproblem_ptr(
427    new sac_problems::point_cloud::PointCloudSacProblem(adapter) );
428
429// run ransac
430ransac.sac_model_ = relposeproblem_ptr;
431ransac.threshold_ = threshold;
432ransac.max_iterations_ = maxIterations;
433ransac.computeModel(0);
434
435// return the result
436transformation_t best_transformation =
437    ransac.model_coefficients_;
438\endcode
439 *
440 * These examples are taken from test_point_cloud.cpp and test_point_cloud_sac.cpp.
441 *
442 * </ul>
443 *
444 * Note that there are more unit-tests in the test-directory. It shows the usage of all the methods contained in the library.
445 *
446 * \section sec_threshold Some words about the sample-consensus-classes
447 *
448 * All the above mentioned Ransac-methods make use of a number of super-classes such that only the basic functions need to be implemented in the derived SacProblem (SampleConsensusProblem). The basic functions are responsible for getting valid samples for model instantiation, model instantiation itself, as well as model verification. <b>SamplesConsensusProblem</b> is the base-class for any problem we want to solve, and contains a virtual interface for the basic methods that need to be implemented. The base-class <b>SampleConsensus</b> is then for the sample-consensus method itself, calling the basic functions. So far only the <b>Ransac</b> is implemented [15].
449 *
450 * \subsection sec_ransac Ransac threshold
451 *
452 * Since the entire library is operating in 3D, we also need a way to compute and threshold reprojection errors in 3D. What we are looking at is the angle \f$ q \f$ between the original bearing-vector \f$ \mathbf{f}_{meas} \f$ and the reprojected one \f$ \mathbf{f}_{repr} \f$. By adopting a certain threshold angle \f$ q_{threshold} \f$, we hence constrain the \f$ \mathbf{f}_{repr} \f$ to lie within a cone of axis \f$ \mathbf{f}_{meas} \f$ and of opening angle \f$ q_{threshold} \f$.
453 *
454 * \image html reprojectionError.png
455 * \image latex reprojectionError.pdf "" width=0.45\columnwidth
456 *
457 * The threshold-angle \f$ q_{threshold} \f$ can be easily obtained from classical reprojection error-thresholds expressed in pixels \f$ \psi \f$ by assuming a certain focal length \f$ l \f$. We then have \f$ q_{threshold} = \arctan{\frac{\psi}{l}} \f$.
458 *
459 * The threshold we are using in the end is still not quite this one, but a value derived from it in analogy with the computation of reprojection errors. The most efficient way to compute a "reprojection error" is given by taking the scalar product of \f$ \mathbf{f}_{meas} \f$ and \f$ \mathbf{f}_{repr} \f$, which equals to \f$ \cos q \f$. Since this value is between -1 and 1, and we actually want an error that minimizes to 0, we take \f$ \epsilon = 1 - \mathbf{f}_{meas}^{T}\mathbf{f}_{repr} = 1 - \cos q \f$. The threshold error is therefore given by
460 *
461 * \f$ \epsilon_{threshold} = 1 - \cos{q_{threshold}} = 1 - \cos({\arctan{\frac{\psi}{l}}}) \f$
462 *
463 * In the ransac-examples in the test-folder, you will often see something like this.
464 *
465\code
466ransac.threshold_ = 1.0 - cos(atan(sqrt(2.0)*0.5/800.0));
467\endcode
468 *
469 * This notably corresponds to the above computation of our "reprojection-error"-threshold, with a focal length of 800.0 and a reprojection error in pixels of 0.5*sqrt(2.0).
470 *
471 * \section sec_multi The "Multi"-stuff
472 *
473 * As you go deeper into the code you might notice that there are a number of elements (mostly in the relative-pose context) that contain the tag "multi" in their name. The adapter base-class used here is called <b>RelativeMultiAdapterBase</b>. The idea of this adapter is to hold multiple sets of bearing-vector correspondences originating from pairs of cameras. A pair of cameras is, as the name says, a set of two cameras in different viewpoints. The correspondences are accessed via a multi-index (a pair-index referring to a specific pair of cameras, and a correspondence-index refering to the correspondence within the camera-pair).
474 *
475 * Subsets of camera-pairs can be identified in a number of problems, such as
476 * <ul>
477 * <li> Non-central relative pose (2 viewpoints): Non-central relative pose problems involving two viewpoints typically originate from motion-estimation with multi-camera rigs. In the special situation where the cameras are pointing in different directions, and where the motion between the viewpoints is not too big (a practically very relevant case), the correspondences are typically originating from the same camera in both viewpoints. We therefore can do a camera-wise grouping of the correspondences in the multi-camera system. The following situation contains four pairs given by the black, green, blue, and orange camera in both viewpoints:
478 *
479 * \image html nonoverlapping.png
480 * \image latex nonoverlapping.pdf "" width=0.8\columnwidth
481 *
482 * <li> Central multi-viewpoint problems: By multi-viewpoint we understand here problems that involve more than two viewpoints. As indicated below, a problem of three central viewpoints for instance allows to identify three camera-pairs as well. The number of camera-pairs in an n-view problem amounts to the combination of 2 out of n, meaning n*(n-1)/2. For the below example, we could have tha camera pairs (c,c'), (c',c''), and (c'',c). The first pair would have a set of correspondences originating from points p1 and p4, the second one from p2 and p4, and the third one from p3 and p4.
483 *
484 * \image html multi_viewpoint.png
485 * \image latex multi_viewpoint.pdf "" width=0.8\columnwidth
486 *
487 * </ul>
488 *
489 * The multi-adapters keep track of these camera-pair-wise correspondence groups. The benefit of it appears when moving towards random sample-consensus schemes. Have a look at the "opengv/sac/"-folder, it contains the <b>MultiSampleConsensus</b>, <b>MultiRansac</b>, and <b>MultiSampleConsensusProblem</b> classes. They employ the multi-indices, and the derived MultiSampleConsensusProblems exploit the fact that the correspondences are grouped:
490 *
491 * <ul>
492 * <li>The <b>MultiNoncentralRelativePoseSacProblem</b> is for non-central, non-overlapping viewpoints with little change, and exploits the grouping in order to do homogeneous sampling of correspondences over the cameras. As an example, imagine we are computing the relative pose of a non-overlapping multi-camera rig with two cameras facing opposite directions. In terms of accuracy, it doesn't make sense to sample 16-points in one camera and one point in the other. We preferrably would like to sample 8 points in one camera, and 9 in the other. This is exactly what MultiNoncentralRelativePoseSacProblem is able to do. It uses the derived adapter <b>NoncentralRelativeMultiAdapter</b>.
493 * <li>In the multi viewpoint case, one could of course solve a central relative pose problem for each camera-pair individually. The idea of <b>MultiCentralRelativePoseSacProblem</b> is to benefit from a joint solution of multiple relative-pose problems. In the above three-view problem for instance, we can exploit additional constraints around the individual transformations such as cycles of rotations returning identity, and cycles of translations returning zero. The corresponding adapter is called <b>CentralRelativeMultiAdapter</b>.
494 * </ul>
495 *
496 * All this stuff is highly experimental, so you probably shouldn't pay too much attention to it for the moment ;)
497 *
498 */
499