11 namespace depth_to_rgb_calibration {
18 throw std::runtime_error(
"failed to open file:\n" + path );
19 f.write( (
char const *)data, cb );
23 double get_norma(
const std::vector< double3 > & vec )
26 std::for_each( vec.begin(), vec.end(), [&](
double3 const &
v ) { sum +=
v.get_norm(); } );
27 return std::sqrt(sum);
32 return rad * 180. / M_PI;
37 return deg * M_PI / 180.;
59 memcpy(&b_A[0], &A[0], 36U *
sizeof(
double));
60 for (i0 = 0; i0 < 6; i0++) {
61 ipiv[i0] = (
signed char)(1 + i0);
64 for (j = 0; j < 5; j++) {
71 smax = std::abs(b_A[b]);
72 for (k = 2; k <=
n; k++) {
74 s = std::abs(b_A[ix]);
81 if (b_A[jj + jy] != 0.0) {
84 ipiv[
j] = (
signed char)(iy + 1);
86 for (k = 0; k < 6; k++) {
96 for (iy = jp1j; iy <= i0; iy++) {
97 b_A[iy - 1] /= b_A[jj];
104 for (b = 0; b <=
n; b++) {
106 if (b_A[jy] != 0.0) {
109 jp1j = (iy -
j) + 12;
110 for (k = i0; k <= jp1j; k++) {
111 b_A[k - 1] += b_A[ix] * -smax;
121 for (iy = 0; iy < 6; iy++) {
125 for (jy = 0; jy < 5; jy++) {
126 if (ipiv[jy] != jy + 1) {
134 for (k = 0; k < 6; k++) {
138 for (iy = i0; iy < 7; iy++) {
139 C[iy - 1] -= C[k] * b_A[(iy + jy) - 1];
144 for (k = 5; k >= 0; k--) {
148 for (iy = 0; iy < k; iy++) {
149 C[iy] -= C[k] * b_A[iy + jy];
164 if (std::abs(A[1]) > std::abs(A[0])) {
175 C[1] = (B[r2] - B[r1] * a21) / (A[2 + r2] - a21 * C_tmp);
176 C[0] = (B[r1] - C[1] * C_tmp) / A[r1];
179 void ndgrid_my(
const double vec1[5],
const double vec2[5],
double yScalingGrid
180 [25],
double xScalingGrid[25])
187 for (k = 0; k < 5; k++) {
188 for (b_k = 0; b_k < 5; b_k++) {
189 yScalingGrid[b_k + 5 * k] = vec1[b_k];
193 for (k = 0; k < 5; k++) {
194 for (b_k = 0; b_k < 5; b_k++) {
195 xScalingGrid[b_k + 5 * k] = vec2[k];
202 void inv(
const double x[9],
double y[9])
212 memcpy(&b_x[0], &x[0], 9U *
sizeof(
double));
216 absx11 = std::abs(x[0]);
217 absx21 = std::abs(x[1]);
218 absx31 = std::abs(x[2]);
219 if ((absx21 > absx11) && (absx21 > absx31)) {
230 if (absx31 > absx11) {
244 b_x[4] -= b_x[1] * b_x[3];
245 b_x[5] -= b_x[2] * b_x[3];
246 b_x[7] -= b_x[1] * b_x[6];
247 b_x[8] -= b_x[2] * b_x[6];
248 if (std::abs(b_x[5]) > std::abs(b_x[4])) {
264 b_x[8] -= b_x[5] * b_x[7];
265 absx11 = (b_x[5] * b_x[1] - b_x[2]) / b_x[8];
266 absx21 = -(b_x[1] + b_x[7] * absx11) / b_x[4];
267 y[
p1] = ((1.0 - b_x[3] * absx21) - b_x[6] * absx11) / b_x[0];
270 absx11 = -b_x[5] / b_x[8];
271 absx21 = (1.0 - b_x[7] * absx11) / b_x[4];
272 y[
p2] = -(b_x[3] * absx21 + b_x[6] * absx11) / b_x[0];
275 absx11 = 1.0 / b_x[8];
276 absx21 = -b_x[7] * absx11 / b_x[4];
277 y[p3] = -(b_x[3] * absx21 + b_x[6] * absx11) / b_x[0];
284 for (
auto i = 0;
i < 3;
i++)
285 for (
auto j = 0;
j < 3;
j++)
286 y[
i * 3 +
j] = x[
j * 3 +
i];
293 for (
int j = 0;
j < int(w);
j++) {
294 for (
int i = 0;
i < int(h);
i++) {
295 B[
i + h *
j] = A[(h * (w - 1 -
j) -
i) + h - 1];
300 std::vector< double >
interp1(
const std::vector< double > &
ind,
301 const std::vector< double > & vals,
302 const std::vector< double > & intrp )
304 std::vector<double>
res(intrp.size(), 0);
306 for (
auto i = 0;
i < intrp.size();
i++)
309 auto it = std::lower_bound(ind.begin(), ind.end(),
value);
310 if (
it == ind.begin())
312 if (*
it == ind.front())
313 res[
i] = ind.front();
315 res[
i] = std::numeric_limits<double>::max();
317 else if (
it == ind.end())
319 if (*
it == ind.back())
322 res[
i] = std::numeric_limits<double>::max();
331 auto target_val1 = vals[ind1];
332 auto target_val2 = vals[ind2];
334 res[
i] = ((val2 -
value) / (val2 - val1))*target_val1 + ((
value - val1) / (val2 - val1))*target_val2;
345 for(
auto i = 0;
i < 3;
i++ )
347 for(
auto j = 0;
j <=
i;
j++ )
353 for(
auto l = 0; l <
i; l++ )
355 sum += res.
mat[
i][l] * res.
mat[
i][l];
357 res.
mat[
i][
i] = sqrt( mat.
mat[i][
j] - sum );
361 for(
auto l = 0; l <
j; l++ )
363 sum += res.
mat[
i][l] * res.
mat[
j][l];
double deg_to_rad(double deg)
GLboolean GLboolean GLboolean b
void inv(const double x[9], double y[9])
void direct_inv_2x2(const double A[4], const double B[2], double C[2])
void write_to_file(void const *data, size_t cb, std::string const &dir, char const *filename)
GLsizei const GLchar *const * path
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
std::vector< double > interp1(const std::vector< double > &ind, const std::vector< double > &vals, const std::vector< double > &intrp)
GLsizei GLsizei GLfloat distance
void transpose(const double x[9], double y[9])
double3x3 cholesky3x3(double3x3 const &mat)
void rotate_180(const uint8_t *A, uint8_t *B, uint32_t w, uint32_t h)
double rad_to_deg(double rad)
const GLuint GLenum const void * binary
double get_norma(const std::vector< double3 > &vec)
void direct_inv_6x6(const double A[36], const double B[6], double C[6])
void ndgrid_my(const double vec1[5], const double vec2[5], double yScalingGrid[25], double xScalingGrid[25])