Blender  V3.3
projection_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008 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 
24 #include "libmv/numeric/numeric.h"
25 #include "testing/testing.h"
26 
27 namespace {
28 using namespace libmv;
29 
31  Mat3 K, Kp;
32  // clang-format off
33  K << 10, 1, 30,
34  0, 20, 40,
35  0, 0, 1;
36  // clang-format on
37 
38  Mat3 R, Rp;
39  // clang-format off
40  R << 1, 0, 0,
41  0, 1, 0,
42  0, 0, 1;
43  // clang-format on
44 
45  Vec3 t, tp;
46  t << 1, 2, 3;
47 
48  Mat34 P;
49  P_From_KRt(K, R, t, &P);
50  KRt_From_P(P, &Kp, &Rp, &tp);
51 
52  EXPECT_MATRIX_NEAR(K, Kp, 1e-8);
53  EXPECT_MATRIX_NEAR(R, Rp, 1e-8);
54  EXPECT_MATRIX_NEAR(t, tp, 1e-8);
55 
56  // TODO(keir): Change the code to ensure det(R) == 1, which is not currently
57  // the case. Also add a test for that here.
58 }
59 
60 Vec4 GetRandomPoint() {
61  Vec4 X;
62  X.setRandom();
63  X(3) = 1;
64  return X;
65 }
66 
68  Mat34 P;
69  // clang-format off
70  P << 1, 0, 0, 0,
71  0, 1, 0, 0,
72  0, 0, 1, 0;
73  // clang-format on
74 
75  Vec4 X_front = GetRandomPoint();
76  Vec4 X_back = GetRandomPoint();
77  X_front(2) = 10; /* Any point in the positive Z direction
78  * where Z > 1 is in front of the camera. */
79  X_back(2) = -10; /* Any point in the negative Z direction
80  * is behind the camera. */
81 
82  bool res_front = isInFrontOfCamera(P, X_front);
83  bool res_back = isInFrontOfCamera(P, X_back);
84 
85  EXPECT_TRUE(res_front);
86  EXPECT_FALSE(res_back);
87 }
88 
89 TEST(AutoCalibration, ProjectionShiftPrincipalPoint) {
90  Mat34 P1, P2;
91  // clang-format off
92  P1 << 1, 0, 0, 0,
93  0, 1, 0, 0,
94  0, 0, 1, 0;
95  P2 << 1, 0, 3, 0,
96  0, 1, 4, 0,
97  0, 0, 1, 0;
98  // clang-format on
99  Mat34 P1_computed, P2_computed;
100  ProjectionShiftPrincipalPoint(P1, Vec2(0, 0), Vec2(3, 4), &P2_computed);
101  ProjectionShiftPrincipalPoint(P2, Vec2(3, 4), Vec2(0, 0), &P1_computed);
102 
103  EXPECT_MATRIX_EQ(P1, P1_computed);
104  EXPECT_MATRIX_EQ(P2, P2_computed);
105 }
106 
107 TEST(AutoCalibration, ProjectionChangeAspectRatio) {
108  Mat34 P1, P2;
109  // clang-format off
110  P1 << 1, 0, 3, 0,
111  0, 1, 4, 0,
112  0, 0, 1, 0;
113  P2 << 1, 0, 3, 0,
114  0, 2, 4, 0,
115  0, 0, 1, 0;
116  // clang-format on
117  Mat34 P1_computed, P2_computed;
118  ProjectionChangeAspectRatio(P1, Vec2(3, 4), 1, 2, &P2_computed);
119  ProjectionChangeAspectRatio(P2, Vec2(3, 4), 2, 1, &P1_computed);
120 
121  EXPECT_MATRIX_EQ(P1, P1_computed);
122  EXPECT_MATRIX_EQ(P2, P2_computed);
123 }
124 
125 } // namespace
#define K(key)
_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 GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define X
Definition: GeomUtils.cpp:199
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
float[3][3] Mat3
Definition: gpu_matrix.cc:27
#define Projection
Definition: gpu_matrix.cc:52
static float P(float k)
Definition: math_interp.c:25
#define R
Eigen::Vector4d Vec4
Definition: numeric.h:107
Eigen::Vector2d Vec2
Definition: numeric.h:105
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
void ProjectionShiftPrincipalPoint(const Mat34 &P, const Vec2 &principal_point, const Vec2 &principal_point_new, Mat34 *P_new)
Definition: projection.cc:135
void KRt_From_P(const Mat34 &P, Mat3 *Kp, Mat3 *Rp, Vec3 *tp)
Definition: projection.cc:32
Eigen::Matrix< double, 3, 4 > Mat34
Definition: numeric.h:73
Eigen::Vector3d Vec3
Definition: numeric.h:106
void ProjectionChangeAspectRatio(const Mat34 &P, const Vec2 &principal_point, double aspect_ratio, double aspect_ratio_new, Mat34 *P_new)
Definition: projection.cc:148
void P_From_KRt(const Mat3 &K, const Mat3 &R, const Vec3 &t, Mat34 *P)
Definition: projection.cc:26
bool isInFrontOfCamera(const Mat34 &P, const Vec4 &X)