ViSP  2.10.0
calibrateTsai.cpp
1 /****************************************************************************
2  *
3  * $Id: calibrateTsai.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  try {
62  // We want to calibrate the hand to eye extrinsic camera parameters from 6 couple of poses: cMo and wMe
63  const unsigned int N = 6;
64  // Input: six couple of poses used as input in the calibration proces
65  std::vector<vpHomogeneousMatrix> cMo(N) ; // eye (camera) to object transformation. The object frame is attached to the calibrartion grid
66  std::vector<vpHomogeneousMatrix> wMe(N) ; // world to hand (end-effector) transformation
67  // Output: Result of the calibration
68  vpHomogeneousMatrix eMc; // hand (end-effector) to eye (camera) transformation
69 
70  // Initialize an eMc transformation used to produce the simulated input transformations cMo and wMe
71  vpTranslationVector etc(0.1, 0.2, 0.3);
72  vpThetaUVector erc;
73  erc[0] = vpMath::rad(10); // 10 deg
74  erc[1] = vpMath::rad(-10); // -10 deg
75  erc[2] = vpMath::rad(25); // 25 deg
76 
77  eMc.buildFrom(etc, erc);
78  std::cout << "Simulated hand to eye transformation: eMc " << std::endl ;
79  std::cout << eMc << std::endl ;
80  std::cout << "Theta U rotation: " << vpMath::deg(erc[0]) << " " << vpMath::deg(erc[1]) << " " << vpMath::deg(erc[2]) << std::endl;
81 
82  vpColVector v_c(6) ; // camera velocity used to produce 6 simulated poses
83  for (unsigned int i=0 ; i < N ; i++)
84  {
85  v_c = 0 ;
86  if (i==0) {
87  // Initialize first poses
88  cMo[0].buildFrom(0, 0, 0.5, 0, 0, 0); // z=0.5 m
89  wMe[0].buildFrom(0, 0, 0, 0, 0, 0); // Id
90  }
91  else if (i==1)
92  v_c[3] = M_PI/8 ;
93  else if (i==2)
94  v_c[4] = M_PI/8 ;
95  else if (i==3)
96  v_c[5] = M_PI/10 ;
97  else if (i==4)
98  v_c[0] = 0.5 ;
99  else if (i==5)
100  v_c[1] = 0.8 ;
101 
102  vpHomogeneousMatrix cMc; // camera displacement
103  cMc = vpExponentialMap::direct(v_c) ; // Compute the camera displacement due to the velocity applied to the camera
104  if (i > 0) {
105  // From the camera displacement cMc, compute the wMe and cMo matrices
106  cMo[i] = cMc.inverse() * cMo[i-1];
107  wMe[i] = wMe[i-1] * eMc * cMc * eMc.inverse();
108  }
109  }
110 
111  if (0) {
112  for (unsigned int i=0 ; i < N ; i++) {
114  wMo = wMe[i] * eMc * cMo[i];
115  std::cout << std::endl << "wMo[" << i << "] " << std::endl ;
116  std::cout << wMo << std::endl ;
117  std::cout << "cMo[" << i << "] " << std::endl ;
118  std::cout << cMo[i] << std::endl ;
119  std::cout << "wMe[" << i << "] " << std::endl ;
120  std::cout << wMe[i] << std::endl ;
121  }
122  }
123 
124  // Reset the eMc matrix to eye
125  eMc.eye();
126 
127  // Compute the eMc hand to eye transformation from six poses
128  // - cMo[6]: camera to object poses as six homogeneous transformations
129  // - wMe[6]: world to hand (end-effector) poses as six homogeneous transformations
130  vpCalibration::calibrationTsai(cMo, wMe, eMc) ;
131 
132  std::cout << std::endl << "Output: hand to eye calibration result: eMc estimated " << std::endl ;
133  std::cout << eMc << std::endl ;
134  eMc.extract(erc);
135  std::cout << "Theta U rotation: " << vpMath::deg(erc[0]) << " " << vpMath::deg(erc[1]) << " " << vpMath::deg(erc[2]) << std::endl;
136  return 0 ;
137  }
138  catch(vpException e) {
139  std::cout << "Catch an exception: " << e << std::endl;
140  return 1 ;
141  }
142 }
143 
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
Definition: vpException.h:76
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.