Blender  V3.3
nviewtriangulation_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2009 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #include <iostream>
22 
23 #include "libmv/base/vector.h"
24 #include "libmv/logging/logging.h"
28 #include "libmv/numeric/numeric.h"
29 #include "testing/testing.h"
30 
31 namespace {
32 
33 using namespace libmv;
34 
35 TEST(NViewTriangulate, FiveViews) {
36  int nviews = 5;
37  int npoints = 6;
38  NViewDataSet d = NRealisticCamerasFull(nviews, npoints);
39 
40  // Collect P matrices together.
41  vector<Mat34> Ps(nviews);
42  for (int j = 0; j < nviews; ++j) {
43  Ps[j] = d.P(j);
44  }
45 
46  for (int i = 0; i < npoints; ++i) {
47  // Collect the image of point i in each frame.
48  Mat2X xs(2, nviews);
49  for (int j = 0; j < nviews; ++j) {
50  xs.col(j) = d.x[j].col(i);
51  }
52  Vec4 X;
53  NViewTriangulate(xs, Ps, &X);
54 
55  // Check reprojection error. Should be nearly zero.
56  for (int j = 0; j < nviews; ++j) {
57  Vec3 x_reprojected = Ps[j] * X;
58  x_reprojected /= x_reprojected(2);
59  double error = (x_reprojected.head(2) - xs.col(j)).norm();
60  EXPECT_NEAR(error, 0.0, 1e-9);
61  }
62  }
63 }
64 
65 TEST(NViewTriangulateAlgebraic, FiveViews) {
66  int nviews = 5;
67  int npoints = 6;
68  NViewDataSet d = NRealisticCamerasFull(nviews, npoints);
69 
70  // Collect P matrices together.
71  vector<Mat34> Ps(nviews);
72  for (int j = 0; j < nviews; ++j) {
73  Ps[j] = d.P(j);
74  }
75 
76  for (int i = 0; i < npoints; ++i) {
77  // Collect the image of point i in each frame.
78  Mat2X xs(2, nviews);
79  for (int j = 0; j < nviews; ++j) {
80  xs.col(j) = d.x[j].col(i);
81  }
82  Vec4 X;
83  NViewTriangulate(xs, Ps, &X);
84 
85  // Check reprojection error. Should be nearly zero.
86  for (int j = 0; j < nviews; ++j) {
87  Vec3 x_reprojected = Ps[j] * X;
88  x_reprojected /= x_reprojected(2);
89  double error = (x_reprojected.head<2>() - xs.col(j)).norm();
90  EXPECT_NEAR(error, 0.0, 1e-9);
91  }
92  }
93 }
94 } // namespace
#define X
Definition: GeomUtils.cpp:199
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition: btVector3.h:263
static void error(const char *str)
Definition: meshlaplacian.c:51
void NViewTriangulateAlgebraic(const Matrix< T, 2, Dynamic > &x, const vector< Matrix< T, 3, 4 >> &Ps, Matrix< T, 4, 1 > *X)
Eigen::Vector4d Vec4
Definition: numeric.h:107
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
Eigen::Vector3d Vec3
Definition: numeric.h:106
void NViewTriangulate(const Matrix< T, 2, Dynamic > &x, const vector< Matrix< T, 3, 4 >> &Ps, Matrix< T, 4, 1 > *X)
NViewDataSet NRealisticCamerasFull(int nviews, int npoints, const nViewDatasetConfigator config)
Eigen::Matrix< double, 2, Eigen::Dynamic > Mat2X
Definition: numeric.h:91