Visual Servoing Platform  version 3.1.0
vpCalibration.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  static void calibrationTsai(const std::vector<vpHomogeneousMatrix> &cMo, const std::vector<vpHomogeneousMatrix> &rMe,
123  vpHomogeneousMatrix &eMc);
124 
126  int clearPoint();
127 
128  void computeStdDeviation(double &deviation, double &deviation_dist);
129  int computeCalibration(vpCalibrationMethodType method, vpHomogeneousMatrix &cMo_est, vpCameraParameters &cam_est,
130  bool verbose = false);
131  static int computeCalibrationMulti(vpCalibrationMethodType method, std::vector<vpCalibration> &table_cal,
132  vpCameraParameters &cam, double &globalReprojectionError, bool verbose = false);
133 
134  static int computeCalibrationTsai(const std::vector<vpCalibration> &table_cal, vpHomogeneousMatrix &eMc,
135  vpHomogeneousMatrix &eMc_dist);
136  double computeStdDeviation(const vpHomogeneousMatrix &cMo_est, const vpCameraParameters &camera);
137  double computeStdDeviation_dist(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam);
138  int displayData(vpImage<unsigned char> &I, vpColor color = vpColor::red, unsigned int thickness = 1,
139  int subsampling_factor = 1);
140  int displayGrid(vpImage<unsigned char> &I, vpColor color = vpColor::yellow, unsigned int thickness = 1,
141  int subsampling_factor = 1);
142 
144  static double getLambda() { return gain; }
145 
147  double getResidual(void) const { return residual; }
149  double getResidual_dist(void) const { return residual_dist; }
151  unsigned int get_npt() const { return npt; }
152 
153  int init();
154 
155  int readData(const char *filename);
156  static int readGrid(const char *filename, unsigned int &n, std::list<double> &oX, std::list<double> &oY,
157  std::list<double> &oZ, bool verbose = false);
158 
160  static void setLambda(const double &lambda) { gain = lambda; }
161  int writeData(const char *filename);
162 
163 private:
164  void computePose(const vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
165  void calibLagrange(vpCameraParameters &cam, vpHomogeneousMatrix &cMo);
166 
168  void calibVVS(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
169 
170  static void calibVVSMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
171  bool verbose = false);
172  static void calibVVSMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
173  double &globalReprojectionError, bool verbose = false);
174  void calibVVSWithDistortion(vpCameraParameters &cam, vpHomogeneousMatrix &cMo, bool verbose = false);
175  static void calibVVSWithDistortionMulti(unsigned int nbPose, vpCalibration table_cal[], vpCameraParameters &cam,
176  bool verbose = false);
177  static void calibVVSWithDistortionMulti(std::vector<vpCalibration> &table_cal, vpCameraParameters &cam,
178  double &globalReprojectionError, bool verbose = false);
179 
180 private:
181  unsigned int npt;
182  std::list<double> LoX, LoY,
183  LoZ;
184  std::list<vpImagePoint> Lip;
185 
186  double residual;
187  double residual_dist;
188 
190  static double threshold;
191  static unsigned int nbIterMax;
192  static double gain;
193 };
194 
195 #endif
196 
197 /*
198  * Local variables:
199  * c-basic-offset: 2
200  * End:
201  */
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
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