1 
2 // Copyright (c) 2010 libmv authors.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to
6 // deal in the Software without restriction, including without limitation the
7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 // sell copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 // IN THE SOFTWARE.
21 
22 // This file is part of OpenMVG, an Open Multiple View Geometry C++ library.
23 
24 // Copyright (c) 2012, 2013 Pierre MOULON.
25 
26 // This Source Code Form is subject to the terms of the Mozilla Public
27 // License, v. 2.0. If a copy of the MPL was not distributed with this
28 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
29 
30 #include "openMVG/multiview/test_data_sets.hpp"
31 #include "openMVG/multiview/triangulation_nview.hpp"
32 
33 #include "testing/testing.h"
34 
35 using namespace openMVG;
36 
TEST(Triangulate_NView,FiveViews)37 TEST(Triangulate_NView, FiveViews) {
38   const int nviews = 5;
39   const int npoints = 6;
40   const NViewDataSet d = NRealisticCamerasRing(nviews, npoints);
41 
42   // Collect P matrices together.
43   std::vector<Mat34> Ps(nviews);
44   for (int j = 0; j < nviews; ++j) {
45     Ps[j] = d.P(j);
46   }
47 
48   for (int i = 0; i < npoints; ++i) {
49     // Collect the image of point i in each frame.
50     Mat3X xs(3, nviews);
51     for (int j = 0; j < nviews; ++j) {
52       xs.col(j) = d._x[j].col(i).homogeneous();
53     }
54     Vec4 X;
55     TriangulateNView(xs, Ps, &X);
56 
57     // Check reprojection error. Should be nearly zero.
58     for (int j = 0; j < nviews; ++j) {
59       const Vec3 x_reprojected = Ps[j]*X;
60       const double error = (x_reprojected.hnormalized() - xs.col(j).hnormalized()).norm();
61       EXPECT_NEAR(error, 0.0, 1e-9);
62     }
63   }
64 }
65 
TEST(Triangulate_NViewAlgebraic,FiveViews)66 TEST(Triangulate_NViewAlgebraic, FiveViews) {
67   const int nviews = 5;
68   const int npoints = 6;
69   const NViewDataSet d = NRealisticCamerasRing(nviews, npoints);
70 
71   // Collect P matrices together.
72   std::vector<Mat34> Ps(nviews);
73   for (int j = 0; j < nviews; ++j) {
74     Ps[j] = d.P(j);
75   }
76 
77   for (int i = 0; i < npoints; ++i) {
78     // Collect the image of point i in each frame.
79     Mat3X xs(3, nviews);
80     for (int j = 0; j < nviews; ++j) {
81       xs.col(j) = d._x[j].col(i).homogeneous();
82     }
83     Vec4 X;
84     EXPECT_TRUE(TriangulateNViewAlgebraic(xs, Ps, &X));
85 
86     // Check reprojection error. Should be nearly zero.
87     for (int j = 0; j < nviews; ++j) {
88       const Vec3 x_reprojected = Ps[j]*X;
89       const double error = (x_reprojected.hnormalized() - xs.col(j).hnormalized()).norm();
90       EXPECT_NEAR(error, 0.0, 1e-9);
91     }
92   }
93 }
94 
95 
96 /* ************************************************************************* */
main()97 int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
98 /* ************************************************************************* */
99