Main MRPT website > C++ reference for MRPT 1.9.9
TCamera.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef TCamera_H
10 #define TCamera_H
11 
17 #include <mrpt/poses/CPose3DQuat.h>
18 
19 namespace mrpt
20 {
21 namespace utils
22 {
23 /** Structure to hold the parameters of a pinhole camera model.
24  * The parameters obtained for one camera resolution can be used for any other
25  * resolution by means of the method TCamera::scaleToResolution()
26  *
27  * \sa mrpt::vision::CCamModel, the application <a
28  * href="http://www.mrpt.org/Application:camera-calib-gui" >camera-calib-gui</a>
29  * for calibrating a camera
30  * \ingroup mrpt_base_grp
31  */
33 {
35 
36  // This must be added for declaration of MEX-related functions
38 
39  public:
40  TCamera() : ncols(640), nrows(480), focalLengthMeters(0)
41  {
42  intrinsicParams.set_unsafe(0, 0, 507.808);
43  intrinsicParams.set_unsafe(1, 1, 507.808);
44  intrinsicParams.set_unsafe(0, 2, 356.2368);
45  intrinsicParams.set_unsafe(1, 2, 252.9216);
46  intrinsicParams.set_unsafe(2, 2, 1);
47  for (size_t i = 0; i < dist.SizeAtCompileTime; i++) dist[i] = 0;
48  }
49 
50  /** @name Camera parameters
51  @{ */
52 
53  /** Camera resolution */
55  /** Matrix of intrinsic parameters (containing the focal length and
56  * principal point coordinates) */
58  /** [k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i:
59  * parameters of tangential distortion (default=0) */
61  /** The focal length of the camera, in meters (can be used among
62  * 'intrinsicParams' to determine the pixel size). */
64 
65  /** @} */
66 
67  /** Rescale all the parameters for a new camera resolution (it raises an
68  * exception if the aspect ratio is modified, which is not permitted).
69  */
70  void scaleToResolution(unsigned int new_ncols, unsigned int new_nrows);
71 
72  /** Save as a config block:
73  * \code
74  * [SECTION]
75  * resolution = [NCOLS NROWS]
76  * cx = CX
77  * cy = CY
78  * fx = FX
79  * fy = FY
80  * dist = [K1 K2 T1 T2 K3]
81  * focal_length = FOCAL_LENGTH
82  * \endcode
83  */
84  void saveToConfigFile(
85  const std::string& section, mrpt::utils::CConfigFileBase& cfg) const;
86 
87  /** Load all the params from a config source, in the format used in
88  * saveToConfigFile(), that is:
89  *
90  * \code
91  * [SECTION]
92  * resolution = [NCOLS NROWS]
93  * cx = CX
94  * cy = CY
95  * fx = FX
96  * fy = FY
97  * dist = [K1 K2 T1 T2 K3]
98  * focal_length = FOCAL_LENGTH [optional field]
99  * \endcode
100  * \exception std::exception on missing fields
101  */
102  void loadFromConfigFile(
103  const std::string& section, const mrpt::utils::CConfigFileBase& cfg);
104  /** overload This signature is consistent with the rest of MRPT APIs */
105  inline void loadFromConfigFile(
106  const mrpt::utils::CConfigFileBase& cfg, const std::string& section)
107  {
108  loadFromConfigFile(section, cfg);
109  }
110 
111  /** Dumps all the parameters as a multi-line string, with the same format
112  * than \a saveToConfigFile. \sa saveToConfigFile */
113  std::string dumpAsText() const;
114 
115  /** Set the matrix of intrinsic params of the camera from the individual
116  * values of focal length and principal point coordinates (in pixels)
117  */
119  double fx, double fy, double cx, double cy)
120  {
121  intrinsicParams.set_unsafe(0, 0, fx);
122  intrinsicParams.set_unsafe(1, 1, fy);
123  intrinsicParams.set_unsafe(0, 2, cx);
124  intrinsicParams.set_unsafe(1, 2, cy);
125  }
126 
127  /** Get the vector of distortion params of the camera */
129  mrpt::math::CMatrixDouble15& distParVector) const
130  {
131  for (size_t i = 0; i < 5; i++) distParVector.set_unsafe(0, i, dist[i]);
132  }
133 
134  /** Get a vector with the distortion params of the camera */
135  inline std::vector<double> getDistortionParamsAsVector() const
136  {
137  std::vector<double> v(5);
138  for (size_t i = 0; i < 5; i++) v[i] = dist[i];
139  return v;
140  }
141 
142  /** Set the whole vector of distortion params of the camera */
144  const mrpt::math::CMatrixDouble15& distParVector)
145  {
146  for (size_t i = 0; i < 5; i++) dist[i] = distParVector.get_unsafe(0, i);
147  }
148 
149  /** Set the whole vector of distortion params of the camera from a 4 or
150  * 5-vector */
151  template <class VECTORLIKE>
152  void setDistortionParamsVector(const VECTORLIKE& distParVector)
153  {
154  size_t N = static_cast<size_t>(distParVector.size());
155  ASSERT_(N == 4 || N == 5)
156  dist[4] = 0; // Default value
157  for (size_t i = 0; i < N; i++) dist[i] = distParVector[i];
158  }
159 
160  /** Set the vector of distortion params of the camera from the individual
161  * values of the distortion coefficients
162  */
164  double k1, double k2, double p1, double p2, double k3 = 0)
165  {
166  dist[0] = k1;
167  dist[1] = k2;
168  dist[2] = p1;
169  dist[3] = p2;
170  dist[4] = k3;
171  }
172 
173  /** Get the value of the principal point x-coordinate (in pixels). */
174  inline double cx() const { return intrinsicParams(0, 2); }
175  /** Get the value of the principal point y-coordinate (in pixels). */
176  inline double cy() const { return intrinsicParams(1, 2); }
177  /** Get the value of the focal length x-value (in pixels). */
178  inline double fx() const { return intrinsicParams(0, 0); }
179  /** Get the value of the focal length y-value (in pixels). */
180  inline double fy() const { return intrinsicParams(1, 1); }
181  /** Set the value of the principal point x-coordinate (in pixels). */
182  inline void cx(double val) { intrinsicParams(0, 2) = val; }
183  /** Set the value of the principal point y-coordinate (in pixels). */
184  inline void cy(double val) { intrinsicParams(1, 2) = val; }
185  /** Set the value of the focal length x-value (in pixels). */
186  inline void fx(double val) { intrinsicParams(0, 0) = val; }
187  /** Set the value of the focal length y-value (in pixels). */
188  inline void fy(double val) { intrinsicParams(1, 1) = val; }
189  /** Get the value of the k1 distortion parameter. */
190  inline double k1() const { return dist[0]; }
191  /** Get the value of the k2 distortion parameter. */
192  inline double k2() const { return dist[1]; }
193  /** Get the value of the p1 distortion parameter. */
194  inline double p1() const { return dist[2]; }
195  /** Get the value of the p2 distortion parameter. */
196  inline double p2() const { return dist[3]; }
197  /** Get the value of the k3 distortion parameter. */
198  inline double k3() const { return dist[4]; }
199  /** Get the value of the k1 distortion parameter. */
200  inline void k1(double val) { dist[0] = val; }
201  /** Get the value of the k2 distortion parameter. */
202  inline void k2(double val) { dist[1] = val; }
203  /** Get the value of the p1 distortion parameter. */
204  inline void p1(double val) { dist[2] = val; }
205  /** Get the value of the p2 distortion parameter. */
206  inline void p2(double val) { dist[3] = val; }
207  /** Get the value of the k3 distortion parameter. */
208  inline void k3(double val) { dist[4] = val; }
209 }; // end class TCamera
210 
213 
214 } // End of namespace
215 } // end of namespace
216 
217 // Add for declaration of mexplus::from template specialization
218 DECLARE_MEXPLUS_FROM(mrpt::utils::TCamera) // Not working at the beginning?
219 #endif
void k1(double val)
Get the value of the k1 distortion parameter.
Definition: TCamera.h:200
void p1(double val)
Get the value of the p1 distortion parameter.
Definition: TCamera.h:204
double focalLengthMeters
The focal length of the camera, in meters (can be used among &#39;intrinsicParams&#39; to determine the pixel...
Definition: TCamera.h:63
double p1() const
Get the value of the p1 distortion parameter.
Definition: TCamera.h:194
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class...
double cy() const
Get the value of the principal point y-coordinate (in pixels).
Definition: TCamera.h:176
void scaleToResolution(unsigned int new_ncols, unsigned int new_nrows)
Rescale all the parameters for a new camera resolution (it raises an exception if the aspect ratio is...
Definition: TCamera.cpp:176
bool operator==(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
Definition: TCamera.cpp:204
void setDistortionParamsVector(const VECTORLIKE &distParVector)
Set the whole vector of distortion params of the camera from a 4 or 5-vector.
Definition: TCamera.h:152
This class allows loading and storing values and vectors of different types from a configuration text...
double fx() const
Get the value of the focal length x-value (in pixels).
Definition: TCamera.h:178
double fy() const
Get the value of the focal length y-value (in pixels).
Definition: TCamera.h:180
double k1() const
Get the value of the k1 distortion parameter.
Definition: TCamera.h:190
bool operator!=(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
Definition: TCamera.cpp:211
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class...
double p2() const
Get the value of the p2 distortion parameter.
Definition: TCamera.h:196
void setDistortionParamsVector(const mrpt::math::CMatrixDouble15 &distParVector)
Set the whole vector of distortion params of the camera.
Definition: TCamera.h:143
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &cfg, const std::string &section)
overload This signature is consistent with the rest of MRPT APIs
Definition: TCamera.h:105
uint32_t ncols
Camera resolution.
Definition: TCamera.h:54
int val
Definition: mrpt_jpeglib.h:955
GLubyte GLubyte b
Definition: glext.h:6279
void fy(double val)
Set the value of the focal length y-value (in pixels).
Definition: TCamera.h:188
GLsizei const GLchar ** string
Definition: glext.h:4101
double cx() const
Get the value of the principal point x-coordinate (in pixels).
Definition: TCamera.h:174
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
Definition: TCamera.h:57
void p2(double val)
Get the value of the p2 distortion parameter.
Definition: TCamera.h:206
std::vector< double > getDistortionParamsAsVector() const
Get a vector with the distortion params of the camera.
Definition: TCamera.h:135
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void k3(double val)
Get the value of the k3 distortion parameter.
Definition: TCamera.h:208
double k3() const
Get the value of the k3 distortion parameter.
Definition: TCamera.h:198
mrpt::math::CArrayDouble< 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
Definition: TCamera.h:60
void k2(double val)
Get the value of the k2 distortion parameter.
Definition: TCamera.h:202
uint32_t nrows
Definition: TCamera.h:54
#define ASSERT_(f)
void cx(double val)
Set the value of the principal point x-coordinate (in pixels).
Definition: TCamera.h:182
void fx(double val)
Set the value of the focal length x-value (in pixels).
Definition: TCamera.h:186
void setDistortionParamsFromValues(double k1, double k2, double p1, double p2, double k3=0)
Set the vector of distortion params of the camera from the individual values of the distortion coeffi...
Definition: TCamera.h:163
std::string dumpAsText() const
Dumps all the parameters as a multi-line string, with the same format than saveToConfigFile.
Definition: TCamera.cpp:27
double k2() const
Get the value of the k2 distortion parameter.
Definition: TCamera.h:192
void cy(double val)
Set the value of the principal point y-coordinate (in pixels).
Definition: TCamera.h:184
unsigned __int32 uint32_t
Definition: rptypes.h:47
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void setIntrinsicParamsFromValues(double fx, double fy, double cx, double cy)
Set the matrix of intrinsic params of the camera from the individual values of focal length and princ...
Definition: TCamera.h:118
void getDistortionParamsVector(mrpt::math::CMatrixDouble15 &distParVector) const
Get the vector of distortion params of the camera.
Definition: TCamera.h:128
void loadFromConfigFile(const std::string &section, const mrpt::utils::CConfigFileBase &cfg)
Load all the params from a config source, in the format used in saveToConfigFile(), that is:
Definition: TCamera.cpp:138
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:32
void saveToConfigFile(const std::string &section, mrpt::utils::CConfigFileBase &cfg) const
Save as a config block:
Definition: TCamera.cpp:117



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019