Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpCalibration.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 calibration.
33  *
34  * Authors:
35  * Eric Marchand
36  * Francois Chaumette
37  * Anthony Saunier
38  *
39  *****************************************************************************/
40 
49 #ifndef vpCalibration_h
50 #define vpCalibration_h
51 
52 #include <list>
53 #include <vector>
54 #include <visp3/core/vpCameraParameters.h>
55 #include <visp3/core/vpDisplay.h>
56 #include <visp3/core/vpExponentialMap.h>
57 #include <visp3/core/vpHomogeneousMatrix.h>
58 #include <visp3/core/vpImage.h>
59 #include <visp3/core/vpImagePoint.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/core/vpMatrix.h>
62 #include <visp3/vision/vpCalibrationException.h>
71 class VISP_EXPORT vpCalibration
72 {
73 public:
77  typedef enum {
78  CALIB_LAGRANGE,
80  CALIB_VIRTUAL_VS,
83  CALIB_VIRTUAL_VS_DIST,
85  CALIB_LAGRANGE_VIRTUAL_VS,
88  CALIB_LAGRANGE_VIRTUAL_VS_DIST,
92 
94  vpHomogeneousMatrix cMo_dist;
96  vpCameraParameters cam;
99  vpCameraParameters cam_dist;
101 
104  vpHomogeneousMatrix eMc;
108 
109  double m_aspect_ratio;
110 
111 public:
112  // Constructor
113  vpCalibration();
114  vpCalibration(const vpCalibration &c);
115 
116  // Destructor
117  virtual ~vpCalibration();
118 
119  // Add a new point in this array
120  int addPoint(double X, double Y, double Z, vpImagePoint &ip);
121 
122  // = operator
123  vpCalibration &operator=(const vpCalibration &twinCalibration);
124 
125 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
126 
130  vp_deprecated static void calibrationTsai(const std::vector<vpHomogeneousMatrix> &cMo,
131  const std::vector<vpHomogeneousMatrix> &rMe, vpHomogeneousMatrix &eMc);
132  vp_deprecated static int computeCalibrationTsai(const std::vector<vpCalibration> &table_cal, vpHomogeneousMatrix &eMc,
133  vpHomogeneousMatrix &eMc_dist);
135 #endif
136 
138  int clearPoint();
139 
140  void computeStdDeviation(double &deviation, double &deviation_dist);
141  int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est,
142  bool verbose = false);
143  static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector<vpCalibration> &table_cal,
144  vpCameraParameters &cam, double &globalReprojectionError, bool verbose = false);
145 
146  double computeStdDeviation(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
147  double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam);
148  int displayData(vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1,
149  int subsampling_factor = 1);
150  int displayGrid(vpImage<unsigned char> &I, vpColor color = vpColor::yellow, unsigned int thickness = 1,
151  int subsampling_factor = 1);
152 
154  static double getLambda() { return gain; }
155 
157  double getResidual(void) const { return residual; }
159  double getResidual_dist(void) const { return residual_dist; }
161  unsigned int get_npt() const { return npt; }
162 
163  int init();
164 
165  int readData(const char *filename);
166  static int readGrid(const char *filename, unsigned int &n, std::list<double> &oX, std::list<double> &oY,
167  std::list<double> &oZ, bool verbose = false);
168 
170  static void setLambda(const double &lambda) { gain = lambda; }
171  void setAspectRatio(double aspect_ratio);
172  int writeData(const char *filename);
173 
174 private:
175  void computePose(const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
176  void calibLagrange(vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
177 
179  void calibVVS(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
180 
181  static void calibVVSMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
182  bool verbose = false, double aspect_ratio = -1);
183  static void calibVVSMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
184  double &globalReprojectionError, bool verbose = false, double aspect_ratio = -1);
185  void calibVVSWithDistortion(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
186  static void calibVVSWithDistortionMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
187  bool verbose = false, double aspect_ratio = -1);
188  static void calibVVSWithDistortionMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
189  double &globalReprojectionError, bool verbose = false,
190  double aspect_ratio = -1);
191 
192 private:
193  unsigned int npt;
194  std::list<double> LoX, LoY,
195  LoZ;
196  std::list<vpImagePoint> Lip;
197 
198  double residual;
199  double residual_dist;
200 
202  static double threshold;
203  static unsigned int nbIterMax;
204  static double gain;
205 };
206 
207 #endif
208 
209 /*
210  * Local variables:
211  * c-basic-offset: 2
212  * End:
213  */
double m_aspect_ratio
Fix aspect ratio (px/py)
double getResidual(void) const
get the residual in pixels
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
static double getLambda()
Set the gain for the virtual visual servoing algorithm.
Tools for perspective camera calibration.
Definition: vpCalibration.h:71
vpHomogeneousMatrix cMo
(as a 3x4 matrix [R T])
Definition: vpCalibration.h:93
static const vpColor red
Definition: vpColor.h:217
static void setLambda(const double &lambda)
set the gain for the virtual visual servoing algorithm
unsigned int get_npt() const
get the number of points
Generic class defining intrinsic camera parameters.
vpHomogeneousMatrix eMc_dist
Position of the camera in end-effector frame using camera parameters with distorsion.
double getResidual_dist(void) const
get the residual for perspective projection with distortion (in pixels)
vpHomogeneousMatrix rMe
reference coordinates (manipulator base coordinates)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
static const vpColor yellow
Definition: vpColor.h:225