Visual Servoing Platform  version 3.5.1 under development (2022-09-30)
vpCameraParameters.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Camera intrinsic parameters.
33  *
34  * Authors:
35  * Eric Marchand
36  * Anthony Saunier
37  *
38  *****************************************************************************/
39 
47 #ifndef vpCameraParameters_H
48 #define vpCameraParameters_H
49 
50 #include <vector>
51 
52 #include <visp3/core/vpColVector.h>
53 #include <visp3/core/vpConfig.h>
54 #include <visp3/core/vpDebug.h>
55 #include <visp3/core/vpMatrix.h>
56 
258 class VISP_EXPORT vpCameraParameters
259 {
262 
263 public:
264  typedef enum {
265  perspectiveProjWithoutDistortion,
267  perspectiveProjWithDistortion,
269  ProjWithKannalaBrandtDistortion
271  } vpCameraParametersProjType;
272 
273  // generic functions
276  vpCameraParameters(double px, double py, double u0, double v0);
277  vpCameraParameters(double px, double py, double u0, double v0, double kud, double kdu);
278  vpCameraParameters(double px, double py, double u0, double v0, const std::vector<double> &distortion_coefficients);
279 
280  vpCameraParameters &operator=(const vpCameraParameters &c);
281  bool operator==(const vpCameraParameters &c) const;
282  bool operator!=(const vpCameraParameters &c) const;
283  virtual ~vpCameraParameters();
284 
285  void init();
286  void init(const vpCameraParameters &c);
287  void initFromCalibrationMatrix(const vpMatrix &_K);
288  void initFromFov(const unsigned int &w, const unsigned int &h, const double &hfov, const double &vfov);
289  void initPersProjWithoutDistortion(double px, double py, double u0, double v0);
290  void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu);
291  void initProjWithKannalaBrandtDistortion(double px, double py, double u0, double v0,
292  const std::vector<double> &distortion_coefficients);
293 
301  inline bool isFovComputed() const { return isFov; }
302 
303  void computeFov(const unsigned int &w, const unsigned int &h);
304 
312  inline double getHorizontalFovAngle() const
313  {
314  if (!isFov) {
315  vpTRACE("Warning: The FOV is not computed, getHorizontalFovAngle() "
316  "won't be significant.");
317  }
318  return m_hFovAngle;
319  }
320 
328  inline double getVerticalFovAngle() const
329  {
330  if (!isFov) {
331  vpTRACE("Warning: The FOV is not computed, getVerticalFovAngle() won't "
332  "be significant.");
333  }
334  return m_vFovAngle;
335  }
336 
349  inline std::vector<vpColVector> getFovNormals() const
350  {
351  if (!isFov) {
352  vpTRACE("Warning: The FOV is not computed, getFovNormals() won't be "
353  "significant.");
354  }
355  return fovNormals;
356  }
357 
358  inline double get_px() const { return px; }
359  inline double get_px_inverse() const { return inv_px; }
360  inline double get_py_inverse() const { return inv_py; }
361  inline double get_py() const { return py; }
362  inline double get_u0() const { return u0; }
363  inline double get_v0() const { return v0; }
364  inline double get_kud() const { return kud; }
365  inline double get_kdu() const { return kdu; }
366  inline std::vector<double> getKannalaBrandtDistortionCoefficients() const { return m_dist_coefs; }
367 
368  inline vpCameraParametersProjType get_projModel() const { return projModel; }
369 
370  vpMatrix get_K() const;
371  vpMatrix get_K_inverse() const;
372 
373  void printParameters();
374  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpCameraParameters &cam);
375 
376 private:
377  static const double DEFAULT_U0_PARAMETER;
378  static const double DEFAULT_V0_PARAMETER;
379  static const double DEFAULT_PX_PARAMETER;
380  static const double DEFAULT_PY_PARAMETER;
381  static const double DEFAULT_KUD_PARAMETER;
382  static const double DEFAULT_KDU_PARAMETER;
383  static const vpCameraParametersProjType DEFAULT_PROJ_TYPE;
384 
385  double px, py;
386  double u0, v0;
387  double kud;
388  double kdu;
389  std::vector<double> m_dist_coefs;
390 
391  unsigned int width;
392  unsigned int height;
393  bool isFov;
394  double m_hFovAngle;
395  double m_vFovAngle;
396  std::vector<vpColVector> fovNormals;
397 
398  double inv_px, inv_py;
399 
400  vpCameraParametersProjType projModel;
401 };
402 
403 #endif
Generic class defining intrinsic camera parameters.
std::vector< double > getKannalaBrandtDistortionCoefficients() const
bool isFovComputed() const
std::vector< vpColVector > getFovNormals() const
double getHorizontalFovAngle() const
double getVerticalFovAngle() const
double get_px_inverse() const
double get_kdu() const
double get_py_inverse() const
vpCameraParametersProjType get_projModel() const
double get_kud() const
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:154
#define vpTRACE
Definition: vpDebug.h:416