Berkeley SfM
triangulation.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: Erik Nelson ( eanelson@eecs.berkeley.edu )
35  * David Fridovich-Keil ( dfk@eecs.berkeley.edu )
36  */
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 //
40 // This file defines methods that can be used to triangulate a point in 3D from
41 // multiple 2D observations.
42 //
43 ///////////////////////////////////////////////////////////////////////////////
44 
45 #ifndef BSFM_GEOMETRY_TRIANGULATION_H
46 #define BSFM_GEOMETRY_TRIANGULATION_H
47 
48 #include "point_3d.h"
49 #include "../camera/camera.h"
50 #include "../matching/feature.h"
51 #include "../matching/feature_match.h"
52 
53 namespace bsfm {
54 
55 // Triangulates a single 3D point from > 2 views. The input assumes that
56 // features correspond to the cameras they were taken from. e.g. features[i] was
57 // taken from cameras[i]. Returns false if:
58 // 1) The number of features and cameras are not equal.
59 // 2) A point cannot be uniquely determined.
60 // 3) The triangulated point does not reproject into all cameras.
61 // This uses the inhomogeneous DLT method from H&Z: Multi-View Geometry, Ch 2.2.
62 bool Triangulate(const FeatureList& features,
63  const std::vector<Camera>& cameras, Point3D& point);
64 
65 // Triangulate the 3D position of a point from a 2D correspondence and two
66 // sets of camera extrinsics and intrinsics. Returns false if:
67 // 1) A point cannot be uniquely determined.
68 // 2) The triangulated point does not reproject into both cameras.
69 // This uses the homogeneous DLT method from H&Z: Multi-View Geometry, Ch 2.2.
70 bool Triangulate(const FeatureMatch& feature_match, const Camera& camera1,
71  const Camera& camera2, Point3D& point);
72 
73 // Repeats the Triangulate() function on a list of feature matches, returning a
74 // list of triangulated 3D points. Returns all triangulated points, even if one
75 // point fails. If triangulating a point fails, that point will be stored as (0,
76 // 0, 0) in 'points'.
77 bool Triangulate(const FeatureMatchList& feature_matches, const Camera& camera1,
78  const Camera& camera2, Point3DList& points);
79 
80 } //\namespace bsfm
81 
82 #endif
std::vector< Point3D > Point3DList
Definition: point_3d.h:100
std::vector< Feature > FeatureList
Definition: feature.h:65
Definition: camera.cpp:50
std::vector< FeatureMatch > FeatureMatchList
Definition: feature_match.h:99
bool Triangulate(const FeatureList &features, const std::vector< Camera > &cameras, Point3D &point)