Blender V4.3
test_data_sets.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
22
23#include <cmath>
24
28
29namespace libmv {
30
33
34 // clang-format off
35 d.K1 << 320, 0, 160,
36 0, 320, 120,
37 0, 0, 1;
38 // clang-format on
39 if (same_K) {
40 d.K2 = d.K1;
41 } else {
42 // clang-format off
43 d.K2 << 360, 0, 170,
44 0, 360, 110,
45 0, 0, 1;
46 // clang-format on
47 }
48 d.R1 = RotationAroundZ(-0.1);
49 d.R2 = RotationAroundX(-0.1);
50 d.t1 << 1, 1, 10;
51 d.t2 << -2, -1, 10;
52 P_From_KRt(d.K1, d.R1, d.t1, &d.P1);
53 P_From_KRt(d.K2, d.R2, d.t2, &d.P2);
54
56
57 d.X.resize(3, 30);
58 d.X.setRandom();
59
60 Project(d.P1, d.X, &d.x1);
61 Project(d.P2, d.X, &d.x2);
62
63 return d;
64}
65
67 int fx, int fy, int cx, int cy, double distance, double jitter_amount) {
68 _fx = fx;
69 _fy = fy;
70 _cx = cx;
71 _cy = cy;
73 _jitter_amount = jitter_amount;
74}
75
77 int npoints,
78 const nViewDatasetConfigator config) {
80 d.n = nviews;
81 d.K.resize(nviews);
82 d.R.resize(nviews);
83 d.t.resize(nviews);
84 d.C.resize(nviews);
85 d.x.resize(nviews);
86 d.x_ids.resize(nviews);
87
88 d.X.resize(3, npoints);
89 d.X.setRandom();
90 d.X *= 0.6;
91
92 Vecu all_point_ids(npoints);
93 for (size_t j = 0; j < npoints; ++j) {
94 all_point_ids[j] = j;
95 }
96
97 for (size_t i = 0; i < nviews; ++i) {
98 Vec3 camera_center, t, jitter, lookdir;
99
100 double theta = i * 2 * M_PI / nviews;
101 camera_center << sin(theta), 0.0, cos(theta);
102 camera_center *= config._dist;
103 d.C[i] = camera_center;
104
105 jitter.setRandom();
106 jitter *= config._jitter_amount / camera_center.norm();
107 lookdir = -camera_center + jitter;
108
109 // clang-format off
110 d.K[i] << config._fx, 0, config._cx,
111 0, config._fy, config._cy,
112 0, 0, 1;
113 // clang-format on
114 d.R[i] = LookAt(lookdir);
115 d.t[i] = -d.R[i] * camera_center;
116 d.x[i] = Project(d.P(i), d.X);
117 d.x_ids[i] = all_point_ids;
118 }
119 return d;
120}
121
123 int npoints,
124 float view_ratio,
125 unsigned min_projections,
126 const nViewDatasetConfigator config) {
127 assert(view_ratio <= 1.0);
128 assert(view_ratio > 0.0);
129 assert(min_projections <= npoints);
130 NViewDataSet d;
131 d.n = nviews;
132 d.K.resize(nviews);
133 d.R.resize(nviews);
134 d.t.resize(nviews);
135 d.C.resize(nviews);
136 d.x.resize(nviews);
137 d.x_ids.resize(nviews);
138
139 d.X.resize(3, npoints);
140 d.X.setRandom();
141 d.X *= 0.6;
142
143 Mat visibility(nviews, npoints);
144 visibility.setZero();
145 Mat randoms(nviews, npoints);
146 randoms.setRandom();
147 randoms = (randoms.array() + 1) / 2.0;
148 unsigned num_visibles = 0;
149 for (size_t i = 0; i < nviews; ++i) {
150 num_visibles = 0;
151 for (size_t j = 0; j < npoints; j++) {
152 if (randoms(i, j) <= view_ratio) {
153 visibility(i, j) = true;
154 num_visibles++;
155 }
156 }
157 if (num_visibles < min_projections) {
158 unsigned num_projections_to_add = min_projections - num_visibles;
159 for (size_t j = 0; j < npoints && num_projections_to_add > 0; ++j) {
160 if (!visibility(i, j)) {
161 num_projections_to_add--;
162 }
163 }
164 num_visibles += num_projections_to_add;
165 }
166 d.x_ids[i].resize(num_visibles);
167 d.x[i].resize(2, num_visibles);
168 }
169
170 size_t j_visible = 0;
171 Vec3 X;
172 for (size_t i = 0; i < nviews; ++i) {
173 Vec3 camera_center, t, jitter, lookdir;
174
175 double theta = i * 2 * M_PI / nviews;
176 camera_center << sin(theta), 0.0, cos(theta);
177 camera_center *= config._dist;
178 d.C[i] = camera_center;
179
180 jitter.setRandom();
181 jitter *= config._jitter_amount / camera_center.norm();
182 lookdir = -camera_center + jitter;
183
184 // clang-format off
185 d.K[i] << config._fx, 0, config._cx,
186 0, config._fy, config._cy,
187 0, 0, 1;
188 // clang-format on
189 d.R[i] = LookAt(lookdir);
190 d.t[i] = -d.R[i] * camera_center;
191 j_visible = 0;
192 for (size_t j = 0; j < npoints; j++) {
193 if (visibility(i, j)) {
194 X = d.X.col(j);
195 d.x[i].col(j_visible) = Project(d.P(i), X);
196 d.x_ids[i][j_visible] = j;
197 j_visible++;
198 }
199 }
200 }
201 return d;
202}
203
204} // namespace libmv
#define M_PI
#define X
ccl_device_inline float3 cos(float3 v)
NViewDataSet NRealisticCamerasSparse(int nviews, int npoints, float view_ratio, unsigned min_projections, const nViewDatasetConfigator config)
void FundamentalFromProjections(const Mat34 &P1, const Mat34 &P2, Mat3 *F)
TwoViewDataSet TwoRealisticCameras(bool same_K)
Mat3 RotationAroundX(double angle)
Definition numeric.cc:25
Eigen::MatrixXd Mat
Definition numeric.h:60
Vec2 Project(const Mat34 &P, const Vec3 &X)
Eigen::Matrix< unsigned int, Eigen::Dynamic, 1 > Vecu
Definition numeric.h:67
Eigen::Vector3d Vec3
Definition numeric.h:106
Mat3 RotationAroundZ(double angle)
Definition numeric.cc:49
NViewDataSet NRealisticCamerasFull(int nviews, int npoints, const nViewDatasetConfigator config)
void P_From_KRt(const Mat3 &K, const Mat3 &R, const Vec3 &t, Mat34 *P)
Definition projection.cc:26
Mat3 LookAt(Vec3 center)
Definition numeric.cc:69
float distance(float a, float b)
vector< Mat2X > x
vector< Vecu > x_ids
double _dist
Camera random position parameters.
int _fx
Internal camera parameters.
nViewDatasetConfigator(int fx=1000, int fy=1000, int cx=500, int cy=500, double distance=1.5, double jitter_amount=0.01)