ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
calibrateTsai.cpp
1 /****************************************************************************
2  *
3  * $Id: calibrateTsai.cpp 4056 2013-01-05 13:04:42Z 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 
49 #include <visp/vpDebug.h>
50 #include <visp/vpParseArgv.h>
51 #include <visp/vpIoTools.h>
52 #include <visp/vpCalibration.h>
53 #include <visp/vpExponentialMap.h>
54 #include <stdio.h>
55 #include <sstream>
56 #include <iomanip>
57 
58 int main()
59 {
60  // We want to calibrate the hand to eye extrinsic camera parameters from 6 couple of poses: cMo and wMe
61  const int N = 6;
62  // Input: six couple of poses used as input in the calibration proces
63  vpHomogeneousMatrix cMo[N] ; // eye (camera) to object transformation. The object frame is attached to the calibrartion grid
64  vpHomogeneousMatrix wMe[N] ; // world to hand (end-effector) transformation
65  // Output: Result of the calibration
66  vpHomogeneousMatrix eMc; // hand (end-effector) to eye (camera) transformation
67 
68  // Initialize an eMc transformation used to produce the simulated input transformations cMo and wMe
69  vpTranslationVector etc(0.1, 0.2, 0.3);
70  vpThetaUVector erc;
71  erc[0] = vpMath::rad(10); // 10 deg
72  erc[1] = vpMath::rad(-10); // -10 deg
73  erc[2] = vpMath::rad(25); // 25 deg
74 
75  eMc.buildFrom(etc, erc);
76  std::cout << "Simulated hand to eye transformation: eMc " << std::endl ;
77  std::cout << eMc << std::endl ;
78  std::cout << "Theta U rotation: " << vpMath::deg(erc[0]) << " " << vpMath::deg(erc[1]) << " " << vpMath::deg(erc[2]) << std::endl;
79 
80  vpColVector v_c(6) ; // camera velocity used to produce 6 simulated poses
81  for (int i=0 ; i < N ; i++)
82  {
83  v_c = 0 ;
84  if (i==0) {
85  // Initialize first poses
86  cMo[0].buildFrom(0, 0, 0.5, 0, 0, 0); // z=0.5 m
87  wMe[0].buildFrom(0, 0, 0, 0, 0, 0); // Id
88  }
89  else if (i==1)
90  v_c[3] = M_PI/8 ;
91  else if (i==2)
92  v_c[4] = M_PI/8 ;
93  else if (i==3)
94  v_c[5] = M_PI/10 ;
95  else if (i==4)
96  v_c[0] = 0.5 ;
97  else if (i==5)
98  v_c[1] = 0.8 ;
99 
100  vpHomogeneousMatrix cMc; // camera displacement
101  cMc = vpExponentialMap::direct(v_c) ; // Compute the camera displacement due to the velocity applied to the camera
102  if (i > 0) {
103  // From the camera displacement cMc, compute the wMe and cMo matrixes
104  cMo[i] = cMc.inverse() * cMo[i-1];
105  wMe[i] = wMe[i-1] * eMc * cMc * eMc.inverse();
106  }
107  }
108 
109  if (0) {
110  for (int i=0 ; i < N ; i++) {
112  wMo = wMe[i] * eMc * cMo[i];
113  std::cout << std::endl << "wMo[" << i << "] " << std::endl ;
114  std::cout << wMo << std::endl ;
115  std::cout << "cMo[" << i << "] " << std::endl ;
116  std::cout << cMo[i] << std::endl ;
117  std::cout << "wMe[" << i << "] " << std::endl ;
118  std::cout << wMe[i] << std::endl ;
119  }
120  }
121 
122  // Reset the eMc matrix to eye
123  eMc.eye();
124 
125  // Compute the eMc hand to eye transformation from six poses
126  // - cMo[6]: camera to object poses as six homogeneous transformations
127  // - wMe[6]: world to hand (end-effector) poses as six homogeneous transformations
128  vpCalibration::calibrationTsai(N, cMo, wMe, eMc) ;
129 
130  std::cout << std::endl << "Output: hand to eye calibration result: eMc estimated " << std::endl ;
131  std::cout << eMc << std::endl ;
132  eMc.extract(erc);
133  std::cout << "Theta U rotation: " << vpMath::deg(erc[0]) << " " << vpMath::deg(erc[1]) << " " << vpMath::deg(erc[2]) << std::endl;
134  return 0 ;
135 }
136 
137 /*
138  * Local variables:
139  * c-basic-offset: 2
140  * End:
141  */