ViSP  2.8.0
calibrateTsai.cpp
1 /****************************************************************************
2  *
3  * $Id: calibrateTsai.cpp 4273 2013-06-25 12:33:27Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Tsai calibration example to estimate hand to eye transformation.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
48 #include <stdio.h>
49 #include <sstream>
50 #include <iomanip>
51 #include <vector>
52 
53 #include <visp/vpDebug.h>
54 #include <visp/vpParseArgv.h>
55 #include <visp/vpIoTools.h>
56 #include <visp/vpCalibration.h>
57 #include <visp/vpExponentialMap.h>
58 
59 int main()
60 {
61  // We want to calibrate the hand to eye extrinsic camera parameters from 6 couple of poses: cMo and wMe
62  const int N = 6;
63  // Input: six couple of poses used as input in the calibration proces
64  std::vector<vpHomogeneousMatrix> cMo(N) ; // eye (camera) to object transformation. The object frame is attached to the calibrartion grid
65  std::vector<vpHomogeneousMatrix> wMe(N) ; // world to hand (end-effector) transformation
66  // Output: Result of the calibration
67  vpHomogeneousMatrix eMc; // hand (end-effector) to eye (camera) transformation
68 
69  // Initialize an eMc transformation used to produce the simulated input transformations cMo and wMe
70  vpTranslationVector etc(0.1, 0.2, 0.3);
71  vpThetaUVector erc;
72  erc[0] = vpMath::rad(10); // 10 deg
73  erc[1] = vpMath::rad(-10); // -10 deg
74  erc[2] = vpMath::rad(25); // 25 deg
75 
76  eMc.buildFrom(etc, erc);
77  std::cout << "Simulated hand to eye transformation: eMc " << std::endl ;
78  std::cout << eMc << std::endl ;
79  std::cout << "Theta U rotation: " << vpMath::deg(erc[0]) << " " << vpMath::deg(erc[1]) << " " << vpMath::deg(erc[2]) << std::endl;
80 
81  vpColVector v_c(6) ; // camera velocity used to produce 6 simulated poses
82  for (int i=0 ; i < N ; i++)
83  {
84  v_c = 0 ;
85  if (i==0) {
86  // Initialize first poses
87  cMo[0].buildFrom(0, 0, 0.5, 0, 0, 0); // z=0.5 m
88  wMe[0].buildFrom(0, 0, 0, 0, 0, 0); // Id
89  }
90  else if (i==1)
91  v_c[3] = M_PI/8 ;
92  else if (i==2)
93  v_c[4] = M_PI/8 ;
94  else if (i==3)
95  v_c[5] = M_PI/10 ;
96  else if (i==4)
97  v_c[0] = 0.5 ;
98  else if (i==5)
99  v_c[1] = 0.8 ;
100 
101  vpHomogeneousMatrix cMc; // camera displacement
102  cMc = vpExponentialMap::direct(v_c) ; // Compute the camera displacement due to the velocity applied to the camera
103  if (i > 0) {
104  // From the camera displacement cMc, compute the wMe and cMo matrices
105  cMo[i] = cMc.inverse() * cMo[i-1];
106  wMe[i] = wMe[i-1] * eMc * cMc * eMc.inverse();
107  }
108  }
109 
110  if (0) {
111  for (int i=0 ; i < N ; i++) {
113  wMo = wMe[i] * eMc * cMo[i];
114  std::cout << std::endl << "wMo[" << i << "] " << std::endl ;
115  std::cout << wMo << std::endl ;
116  std::cout << "cMo[" << i << "] " << std::endl ;
117  std::cout << cMo[i] << std::endl ;
118  std::cout << "wMe[" << i << "] " << std::endl ;
119  std::cout << wMe[i] << std::endl ;
120  }
121  }
122 
123  // Reset the eMc matrix to eye
124  eMc.eye();
125 
126  // Compute the eMc hand to eye transformation from six poses
127  // - cMo[6]: camera to object poses as six homogeneous transformations
128  // - wMe[6]: world to hand (end-effector) poses as six homogeneous transformations
129  vpCalibration::calibrationTsai(cMo, wMe, eMc) ;
130 
131  std::cout << std::endl << "Output: hand to eye calibration result: eMc estimated " << std::endl ;
132  std::cout << eMc << std::endl ;
133  eMc.extract(erc);
134  std::cout << "Theta U rotation: " << vpMath::deg(erc[0]) << " " << vpMath::deg(erc[1]) << " " << vpMath::deg(erc[2]) << std::endl;
135  return 0 ;
136 }
137 
138 /*
139  * Local variables:
140  * c-basic-offset: 2
141  * End:
142  */
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
void extract(vpRotationMatrix &R) const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Construction from translation vector and rotation matrix.
static double rad(double deg)
Definition: vpMath.h:100
static void calibrationTsai(std::vector< vpHomogeneousMatrix > &cMo, std::vector< vpHomogeneousMatrix > &rMe, vpHomogeneousMatrix &eMc)
calibration method of effector-camera from R. Tsai and R. Lorenz .
static double deg(double rad)
Definition: vpMath.h:93
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix direct(const vpColVector &v)
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.