Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
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 
42 #ifndef vpCalibration_h
43 #define vpCalibration_h
44 
45 #include <list>
46 #include <vector>
47 #include <visp3/core/vpCameraParameters.h>
48 #include <visp3/core/vpDisplay.h>
49 #include <visp3/core/vpExponentialMap.h>
50 #include <visp3/core/vpHomogeneousMatrix.h>
51 #include <visp3/core/vpImage.h>
52 #include <visp3/core/vpImagePoint.h>
53 #include <visp3/core/vpMath.h>
54 #include <visp3/core/vpMatrix.h>
55 #include <visp3/vision/vpCalibrationException.h>
63 class VISP_EXPORT vpCalibration
64 {
65 public:
69  typedef enum
70  {
71  CALIB_LAGRANGE,
73  CALIB_VIRTUAL_VS,
76  CALIB_VIRTUAL_VS_DIST,
78  CALIB_LAGRANGE_VIRTUAL_VS,
81  CALIB_LAGRANGE_VIRTUAL_VS_DIST,
84  } vpCalibrationMethodType;
85 
103 
120 
121 public:
125  vpCalibration();
126 
130  vpCalibration(const vpCalibration &c);
131 
135  virtual ~vpCalibration();
136 
142  int addPoint(double X, double Y, double Z, vpImagePoint &ip);
143 
149  vpCalibration &operator=(const vpCalibration &twinCalibration);
150 
151 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
156  vp_deprecated static void calibrationTsai(const std::vector<vpHomogeneousMatrix> &cMo,
157  const std::vector<vpHomogeneousMatrix> &rMe, vpHomogeneousMatrix &eMc);
158  vp_deprecated static int computeCalibrationTsai(const std::vector<vpCalibration> &table_cal, vpHomogeneousMatrix &eMc,
159  vpHomogeneousMatrix &eMc_dist);
161 #endif
162 
166  int clearPoint();
167 
179  int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est,
180  bool verbose = false);
181 
196  static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector<vpCalibration> &table_cal,
197  vpCameraParameters &cam_est, double &globalReprojectionError, bool verbose = false);
198 
207  void computeStdDeviation(double &deviation, double &deviation_dist);
208 
218  double computeStdDeviation(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
219 
228  double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
229 
240  int displayData(vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1,
241  int subsampling_factor = 1);
242 
253  int displayGrid(vpImage<unsigned char> &I, vpColor color = vpColor::yellow, unsigned int thickness = 1,
254  int subsampling_factor = 1);
255 
257  static double getLambda() { return gain; }
258 
262  double getResidual(void) const { return residual; }
263 
267  double getResidual_dist(void) const { return residual_dist; }
268 
272  unsigned int get_npt() const { return npt; }
273 
277  int init();
278 
285  int readData(const std::string &filename);
286 
302  static int readGrid(const std::string &filename, unsigned int &n, std::list<double> &oX, std::list<double> &oY,
303  std::list<double> &oZ, bool verbose = false);
304 
308  static void setLambda(const double &lambda) { gain = lambda; }
309 
316  void setAspectRatio(double aspect_ratio);
317 
325  int writeData(const std::string &filename);
326 
327 private:
328  void computePose(const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
329  void calibLagrange(vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
330 
332  void calibVVS(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
333 
334  static void calibVVSMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
335  bool verbose = false, double aspect_ratio = -1);
336  static void calibVVSMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
337  double &globalReprojectionError, bool verbose = false, double aspect_ratio = -1);
338  void calibVVSWithDistortion(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
339  static void calibVVSWithDistortionMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
340  bool verbose = false, double aspect_ratio = -1);
341  static void calibVVSWithDistortionMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
342  double &globalReprojectionError, bool verbose = false,
343  double aspect_ratio = -1);
344 
345 private:
346  unsigned int npt;
347  std::list<double> LoX, LoY,
348  LoZ;
349  std::list<vpImagePoint> Lip;
350 
351  double residual;
352  double residual_dist;
354 
355  static double threshold;
356  static unsigned int nbIterMax;
357  static double gain;
358 };
359 
360 #endif
Tools for perspective camera calibration.
Definition: vpCalibration.h:64
static void setLambda(const double &lambda)
static double getLambda()
Set the gain for 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:89
vpCameraParameters cam_dist
double getResidual_dist(void) const
vpHomogeneousMatrix eMc
vpHomogeneousMatrix cMo_dist
Definition: vpCalibration.h:94
vpCameraParameters cam
Definition: vpCalibration.h:98
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