Visual Servoing Platform  version 3.2.1 under development (2019-10-18) under development (2019-10-18)
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;
107 
108 public:
109  // Constructor
110  vpCalibration();
111  vpCalibration(const vpCalibration &c);
112 
113  // Destructor
114  virtual ~vpCalibration();
115 
116  // Add a new point in this array
117  int addPoint(double X, double Y, double Z, vpImagePoint &ip);
118 
119  // = operator
120  vpCalibration &operator=(const vpCalibration &twinCalibration);
121 
122 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
123 
127  vp_deprecated static void calibrationTsai(const std::vector<vpHomogeneousMatrix> &cMo,
128  const std::vector<vpHomogeneousMatrix> &rMe,
129  vpHomogeneousMatrix &eMc);
130  vp_deprecated static int computeCalibrationTsai(const std::vector<vpCalibration> &table_cal, vpHomogeneousMatrix &eMc,
131  vpHomogeneousMatrix &eMc_dist);
133  #endif
134 
136  int clearPoint();
137 
138  void computeStdDeviation(double &deviation, double &deviation_dist);
139  int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est,
140  bool verbose = false);
141  static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector<vpCalibration> &table_cal,
142  vpCameraParameters &cam, double &globalReprojectionError, bool verbose = false);
143 
144  double computeStdDeviation(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
145  double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam);
146  int displayData(vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1,
147  int subsampling_factor = 1);
148  int displayGrid(vpImage<unsigned char> &I, vpColor color = vpColor::yellow, unsigned int thickness = 1,
149  int subsampling_factor = 1);
150 
152  static double getLambda() { return gain; }
153 
155  double getResidual(void) const { return residual; }
157  double getResidual_dist(void) const { return residual_dist; }
159  unsigned int get_npt() const { return npt; }
160 
161  int init();
162 
163  int readData(const char *filename);
164  static int readGrid(const char *filename, unsigned int &n, std::list<double> &oX, std::list<double> &oY,
165  std::list<double> &oZ, bool verbose = false);
166 
168  static void setLambda(const double &lambda) { gain = lambda; }
169  int writeData(const char *filename);
170 
171 private:
172  void computePose(const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
173  void calibLagrange(vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
174 
176  void calibVVS(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
177 
178  static void calibVVSMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
179  bool verbose = false);
180  static void calibVVSMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
181  double &globalReprojectionError, bool verbose = false);
182  void calibVVSWithDistortion(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
183  static void calibVVSWithDistortionMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
184  bool verbose = false);
185  static void calibVVSWithDistortionMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
186  double &globalReprojectionError, bool verbose = false);
187 
188 private:
189  unsigned int npt;
190  std::list<double> LoX, LoY,
191  LoZ;
192  std::list<vpImagePoint> Lip;
193 
194  double residual;
195  double residual_dist;
196 
198  static double threshold;
199  static unsigned int nbIterMax;
200  static double gain;
201 };
202 
203 #endif
204 
205 /*
206  * Local variables:
207  * c-basic-offset: 2
208  * End:
209  */
double getResidual(void) const
get the residual in pixels
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
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:180
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:88
static const vpColor yellow
Definition: vpColor.h:188