Blender V4.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
26#include "testing/testing.h"
27
28namespace libmv {
29namespace {
30
31TEST(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
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
52TEST(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
67TEST(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
105TEST(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
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
float[3][3] Mat3
Definition gpu_matrix.cc:28
#define LOG(severity)
Definition log.h:33
ccl_device_inline float3 cos(float3 v)
#define R
#define H(x, y, z)
T asin(const T &a)
T sin(const AngleRadianBase< T > &a)
Eigen::VectorXd Vec
Definition numeric.h:61
void EuclideanToHomogeneous(const Mat &X, Mat *H)
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)