Visual Servoing Platform  version 3.6.1 under development (2024-04-24)
vpCalibration.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Camera calibration.
32  */
33 
38 #ifndef vpCalibration_h
39 #define vpCalibration_h
40 
41 #include <list>
42 #include <vector>
43 #include <visp3/core/vpCameraParameters.h>
44 #include <visp3/core/vpDisplay.h>
45 #include <visp3/core/vpExponentialMap.h>
46 #include <visp3/core/vpHomogeneousMatrix.h>
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpImagePoint.h>
49 #include <visp3/core/vpMath.h>
50 #include <visp3/core/vpMatrix.h>
51 #include <visp3/vision/vpCalibrationException.h>
52 
60 class VISP_EXPORT vpCalibration
61 {
62 public:
66  typedef enum
67  {
68  CALIB_LAGRANGE,
70  CALIB_VIRTUAL_VS,
73  CALIB_VIRTUAL_VS_DIST,
75  CALIB_LAGRANGE_VIRTUAL_VS,
78  CALIB_LAGRANGE_VIRTUAL_VS_DIST,
81  } vpCalibrationMethodType;
82 
100 
113 
118 
122  vpCalibration();
123 
127  vpCalibration(const vpCalibration &c);
128 
132  virtual ~vpCalibration();
133 
139  int addPoint(double X, double Y, double Z, vpImagePoint &ip);
140 
146  vpCalibration &operator=(const vpCalibration &twinCalibration);
147 
151  int clearPoint();
152 
164  int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est,
165  bool verbose = false);
166 
181  static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector<vpCalibration> &table_cal,
182  vpCameraParameters &cam_est, double &globalReprojectionError, bool verbose = false);
183 
192  void computeStdDeviation(double &deviation, double &deviation_dist);
193 
203  double computeStdDeviation(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
204 
213  double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
214 
225  int displayData(vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1,
226  int subsampling_factor = 1);
227 
238  int displayGrid(vpImage<unsigned char> &I, vpColor color = vpColor::yellow, unsigned int thickness = 1,
239  int subsampling_factor = 1);
240 
242  static double getLambda() { return m_gain; }
243 
247  double getResidual(void) const { return m_residual; }
248 
252  double getResidual_dist(void) const { return m_residual_dist; }
253 
257  unsigned int get_npt() const { return m_npt; }
258 
262  int init();
263 
270  int readData(const std::string &filename);
271 
287  static int readGrid(const std::string &filename, unsigned int &n, std::list<double> &oX, std::list<double> &oY,
288  std::list<double> &oZ, bool verbose = false);
289 
293  static void setLambda(const double &lambda) { m_gain = lambda; }
294 
301  void setAspectRatio(double aspect_ratio);
302 
310  int writeData(const std::string &filename);
311 
312 private:
313  void computePose(const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
314  void calibLagrange(vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
315 
317  void calibVVS(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
318 
319  static void calibVVSMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
320  bool verbose = false, double aspect_ratio = -1);
321  static void calibVVSMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
322  double &globalReprojectionError, bool verbose = false, double aspect_ratio = -1);
323  void calibVVSWithDistortion(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
324  static void calibVVSWithDistortionMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
325  bool verbose = false, double aspect_ratio = -1);
326  static void calibVVSWithDistortionMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
327  double &globalReprojectionError, bool verbose = false,
328  double aspect_ratio = -1);
329 
330  unsigned int m_npt;
331  std::list<double> m_LoX, m_LoY, m_LoZ;
332  std::list<vpImagePoint> m_Lip;
333 
334  double m_residual;
335  double m_residual_dist;
337 
338  static double m_threshold;
339  static unsigned int m_nbIterMax;
340  static double m_gain;
341 };
342 
343 #endif
Tools for perspective camera calibration.
Definition: vpCalibration.h:61
static void setLambda(const double &lambda)
static double getLambda()
Get the gain of the virtual visual servoing algorithm.
unsigned int get_npt() const
double m_aspect_ratio
double getResidual(void) const
vpHomogeneousMatrix eMc_dist
vpHomogeneousMatrix rMe
vpHomogeneousMatrix cMo
Definition: vpCalibration.h:86
vpCameraParameters cam_dist
Definition: vpCalibration.h:99
double getResidual_dist(void) const
vpHomogeneousMatrix eMc
vpHomogeneousMatrix cMo_dist
Definition: vpCalibration.h:91
vpCameraParameters cam
Definition: vpCalibration.h:95
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor red
Definition: vpColor.h:211
static const vpColor yellow
Definition: vpColor.h:219
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82