PICCANTE  0.4
The hottest HDR imaging library!
intrisics_matrix.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_COMPUTER_VISION_INTRISICS_MATRIX_HPP
19 #define PIC_COMPUTER_VISION_INTRISICS_MATRIX_HPP
20 
21 #include <vector>
22 #include <random>
23 #include <stdlib.h>
24 
25 #include "../base.hpp"
26 
27 #include "../util/math.hpp"
28 
29 #ifndef PIC_DISABLE_EIGEN
30 
31  #ifndef PIC_EIGEN_NOT_BUNDLED
32  #include "../externals/Eigen/Dense"
33  #include "../externals/Eigen/Geometry"
34  #else
35  #include <Eigen/Dense>
36  #include <Eigen/Geometry>
37  #endif
38 
39 #endif
40 
41 namespace pic {
42 
49 {
50  return 1.0 / tan(fovy / 2.0);
51 }
52 
60 PIC_INLINE double getFOVAngleFromFocalSensor(double f, double x, double y)
61 {
62  double d = sqrt(x * x + y * y);
63  return 2.0 * atan(d / (2.0 * f));
64 }
65 
73 PIC_INLINE double getFocalLengthPixels(double focal_length_mm, double sensor_size_mm, double sensor_size_px)
74 {
75  return (focal_length_mm * sensor_size_px) / sensor_size_mm;
76 }
77 
78 #ifndef PIC_DISABLE_EIGEN
79 
89 PIC_INLINE Eigen::Matrix3d getIntrinsicsMatrix(double focal_length, double m_x, double m_y, double opitical_center_x, double opitical_center_y)
90 {
91  Eigen::Matrix3d K;
92  K.setZero();
93  K(0, 0) = focal_length * m_x;
94  K(1, 1) = focal_length * m_y;
95  K(2, 2) = 1.0;
96 
97  K(0, 2) = opitical_center_x;
98  K(1, 2) = opitical_center_y;
99 
100  return K;
101 }
102 
110 PIC_INLINE Eigen::Matrix3d getIntrinsicsMatrix(double focal_length_x, double focal_length_y, double opitical_center_x, double opitical_center_y)
111 {
112  Eigen::Matrix3d K;
113  K.setZero();
114  K(0, 0) = focal_length_x;
115  K(1, 1) = focal_length_y;
116  K(2, 2) = 1.0;
117 
118  K(0, 2) = opitical_center_x;
119  K(1, 2) = opitical_center_y;
120 
121  return K;
122 }
123 
130 PIC_INLINE Eigen::Vector2d removeLensDistortion(Eigen::Vector2d &p, double k[5])
131 {
132  Eigen::Vector2d ret;
133 
134  double r_2 = p[0] * p[0] + p[1] * p[1];
135  double r_4 = r_2 * r_2;
136 
137  double c = 1.0 + k[0] * r_2 + k[1] * r_4 + k[4] * r_4 *r_2;
138 
139  Eigen::Vector2d dx;
140  dx[0] = 2 * k[2] * p[0] * p[1] + k[3] * (r_2 + 2.0 * p[0] * p[0]);
141  dx[1] = k[2] * (r_2 + 2 * p[1] * p[1]) + 2.0 * k[3] * p[0] * p[1];
142 
143  ret = p * c + dx;
144 
145  return ret;
146 }
147 
148 #endif // PIC_DISABLE_EIGEN
149 
150 } // end namespace pic
151 
152 #endif // PIC_COMPUTER_VISION_INTRISICS_MATRIX_HPP
PIC_INLINE double getFocalLengthFromFOVAngle(double fovy)
getFocalLengthFromFOVAngle
Definition: intrisics_matrix.hpp:48
PIC_INLINE Eigen::Vector2d removeLensDistortion(Eigen::Vector2d &p, double k[5])
removeLensDistortion
Definition: intrisics_matrix.hpp:130
PIC_INLINE double getFOVAngleFromFocalSensor(double f, double x, double y)
getFOVAngleFromFocalSensor
Definition: intrisics_matrix.hpp:60
#define PIC_INLINE
Definition: base.hpp:33
PIC_INLINE double getFocalLengthPixels(double focal_length_mm, double sensor_size_mm, double sensor_size_px)
getFocalLengthPixels
Definition: intrisics_matrix.hpp:73
Definition: bilateral_separation.hpp:25
PIC_INLINE Eigen::Matrix3d getIntrinsicsMatrix(double focal_length, double m_x, double m_y, double opitical_center_x, double opitical_center_y)
getIntrinsicsMatrix
Definition: intrisics_matrix.hpp:89