Blender  V3.3
panography_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 
22 #include "libmv/logging/logging.h"
25 #include "libmv/numeric/numeric.h"
26 #include "testing/testing.h"
27 
28 namespace libmv {
29 namespace {
30 
31 TEST(Panography, PrintSomeSharedFocalEstimationValues) {
32  Mat x1(2, 2), x2(2, 2);
33  x1 << 158, 78, 124, 113;
34  x2 << 300, 214, 125, 114;
35 
36  // Normalize data (set principal point 0,0 and image border to 1.0).
37  x1.block<1, 2>(0, 0) /= 320;
38  x1.block<1, 2>(1, 0) /= 240;
39  x2.block<1, 2>(0, 0) /= 320;
40  x2.block<1, 2>(1, 0) /= 240;
41  x1 += Mat2::Constant(0.5);
42  x2 += Mat2::Constant(0.5);
43 
44  vector<double> fs;
46 
47  // Assert we found a valid solution.
48  EXPECT_EQ(1, fs.size());
49  EXPECT_NEAR(3.47194, fs[0], 1e-3);
50 }
51 
52 TEST(Panography, GetR_FixedCameraCenterWithIdentity) {
53  Mat x1(3, 3);
54  // clang-format off
55  x1 << 0.5, 0.6, 0.7,
56  0.5, 0.5, 0.4,
57  10.0, 10.0, 10.0;
58  // clang-format on
59 
60  Mat3 R;
61  GetR_FixedCameraCenter(x1, x1, 1.0, &R);
62  R /= R(2, 2);
63  EXPECT_MATRIX_NEAR(Mat3::Identity(), R, 1e-8);
64  LOG(INFO) << "R \n" << R;
65 }
66 
67 TEST(Panography, Homography_GetR_Test_PitchY30) {
68  int n = 3;
69 
70  Mat x1(3, n);
71  // clang-format off
72  x1 << 0.5, 0.6, 0.7,
73  0.5, 0.5, 0.4,
74  10, 10, 10;
75  // clang-format on
76 
77  Mat x2 = x1;
78  const double alpha = 30.0 * M_PI / 180.0;
79  Mat3 rotY;
80  // clang-format off
81  rotY << cos(alpha), 0, -sin(alpha),
82  0, 1, 0,
83  sin(alpha), 0, cos(alpha);
84  // clang-format on
85 
86  for (int i = 0; i < n; ++i) {
87  x2.block<3, 1>(0, i) = rotY * x1.col(i);
88  }
89 
90  Mat3 R;
91  GetR_FixedCameraCenter(x1, x2, 1.0, &R);
92 
93  // Assert that residuals are small enough
94  for (int i = 0; i < n; ++i) {
95  Vec residuals = (R * x1.col(i)) - x2.col(i);
96  EXPECT_NEAR(0, residuals.norm(), 1e-6);
97  }
98 
99  // Check that the rotation angle along Y is the expected one.
100  // Use the euler approximation to recover the angle.
101  double pitch_y = asin(R(2, 0)) * 180.0 / M_PI;
102  EXPECT_NEAR(30, pitch_y, 1e-4);
103 }
104 
105 TEST(MinimalPanoramic, Real_Case_Kernel) {
106  const int n = 2;
107  Mat x1(2, n); // From image 0.jpg
108  // clang-format off
109  x1<< 158, 78,
110  124, 113;
111  // clang-format on
112 
113  Mat x2(2, n); // From image 3.jpg
114  // clang-format off
115  x2<< 300, 214,
116  125, 114;
117  // clang-format on
118 
119  Mat3 Ground_TruthHomography;
120  // clang-format off
121  Ground_TruthHomography<< 1, 0.02, 129.83,
122  -0.02, 1.012, 0.07823,
123  0, 0, 1;
124  // clang-format on
125 
126  vector<Mat3> Hs;
127 
129 
130  LOG(INFO) << "Got " << Hs.size() << " solutions.";
131  for (int j = 0; j < Hs.size(); ++j) {
132  Mat3 H = Hs[j];
133 
134  EXPECT_MATRIX_NEAR(H, Ground_TruthHomography, 1e-1);
135 
136  Mat x1h, x2h;
137  EuclideanToHomogeneous(x1, &x1h);
138  EuclideanToHomogeneous(x2, &x2h);
139 
140  // Assert that residuals are small enough
141  for (int i = 0; i < n; ++i) {
142  Vec x1p = H * x1h.col(i);
143  Vec residuals = x1p / x1p(2) - x2h.col(i);
144  EXPECT_MATRIX_NEAR_ZERO(residuals, 1e-5);
145  }
146  }
147 }
148 
149 } // namespace
150 } // namespace libmv
151 
152 // TODO(pmoulon): Add a real test case based on images.
153 // TODO(pmoulon): Add a check for the actual f value for the real images.
154 // TODO(pmoulon): Add a test that has some inliers and outliers.
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define M_PI
Definition: BLI_math_base.h:20
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
float[3][3] Mat3
Definition: gpu_matrix.cc:27
#define LOG(severity)
Definition: log.h:36
#define R
#define H(x, y, z)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
Definition: rall1d.h:391
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
Eigen::VectorXd Vec
Definition: numeric.h:61
void EuclideanToHomogeneous(const Mat &X, Mat *H)
Definition: projection.cc:200
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
void F_FromCorrespondance_2points(const Mat &x1, const Mat &x2, vector< double > *fs)
Definition: panography.cc:73
Eigen::MatrixXd Mat
Definition: numeric.h:60
void GetR_FixedCameraCenter(const Mat &x1, const Mat &x2, const double focal, Mat3 *R)
Definition: panography.cc:99
static void Solve(const Mat &x1, const Mat &x2, vector< Mat3 > *Hs)