Visual Servoing Platform  version 3.6.1 under development (2024-10-10)
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 
53 BEGIN_VISP_NAMESPACE
61 class VISP_EXPORT vpCalibration
62 {
63 public:
67  typedef enum
68  {
69  CALIB_LAGRANGE,
71  CALIB_VIRTUAL_VS,
74  CALIB_VIRTUAL_VS_DIST,
76  CALIB_LAGRANGE_VIRTUAL_VS,
79  CALIB_LAGRANGE_VIRTUAL_VS_DIST,
82  } vpCalibrationMethodType;
83 
101 
114 
119 
123  vpCalibration();
124 
128  vpCalibration(const vpCalibration &c);
129 
133  virtual ~vpCalibration();
134 
140  int addPoint(double X, double Y, double Z, vpImagePoint &ip);
141 
147  vpCalibration &operator=(const vpCalibration &twinCalibration);
148 
152  int clearPoint();
153 
165  int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est,
166  bool verbose = false);
167 
182  static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector<vpCalibration> &table_cal,
183  vpCameraParameters &cam_est, double &globalReprojectionError, bool verbose = false);
184 
193  void computeStdDeviation(double &deviation, double &deviation_dist);
194 
204  double computeStdDeviation(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
205 
214  double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
215 
226  int displayData(vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1,
227  int subsampling_factor = 1);
228 
239  int displayGrid(vpImage<unsigned char> &I, vpColor color = vpColor::yellow, unsigned int thickness = 1,
240  int subsampling_factor = 1);
241 
243  static double getLambda() { return m_gain; }
244 
248  double getResidual(void) const { return m_residual; }
249 
253  double getResidual_dist(void) const { return m_residual_dist; }
254 
258  unsigned int get_npt() const { return m_npt; }
259 
263  int init();
264 
271  int readData(const std::string &filename);
272 
288  static int readGrid(const std::string &filename, unsigned int &n, std::list<double> &oX, std::list<double> &oY,
289  std::list<double> &oZ, bool verbose = false);
290 
294  static void setLambda(const double &lambda) { m_gain = lambda; }
295 
302  void setAspectRatio(double aspect_ratio);
303 
311  int writeData(const std::string &filename);
312 
313 private:
314  void computePose(const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
315  void calibLagrange(vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
316 
318  void calibVVS(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
319 
320  static void calibVVSMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
321  bool verbose = false, double aspect_ratio = -1);
322  static void calibVVSMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
323  double &globalReprojectionError, bool verbose = false, double aspect_ratio = -1);
324  void calibVVSWithDistortion(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
325  static void calibVVSWithDistortionMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
326  bool verbose = false, double aspect_ratio = -1);
327  static void calibVVSWithDistortionMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
328  double &globalReprojectionError, bool verbose = false,
329  double aspect_ratio = -1);
330 
331  unsigned int m_npt;
332  std::list<double> m_LoX, m_LoY, m_LoZ;
333  std::list<vpImagePoint> m_Lip;
334 
335  double m_residual;
336  double m_residual_dist;
338 
339  static double m_threshold;
340  static unsigned int m_nbIterMax;
341  static double m_gain;
342 };
343 END_VISP_NAMESPACE
344 #endif
Tools for perspective camera calibration.
Definition: vpCalibration.h:62
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:87
vpCameraParameters cam_dist
double getResidual_dist(void) const
vpHomogeneousMatrix eMc
vpHomogeneousMatrix cMo_dist
Definition: vpCalibration.h:92
vpCameraParameters cam
Definition: vpCalibration.h:96
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor red
Definition: vpColor.h:217
static const vpColor yellow
Definition: vpColor.h:225
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