Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testCameraParametersConversion.cpp
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Performs various tests on the vpPixelMeterConversion and
32  * vpPixelMeterConversion class.
33  *
34  * Authors:
35  * Anthony saunier
36  *
37  *****************************************************************************/
38 
39 
40 
48 #include <visp3/core/vpMath.h>
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpCameraParameters.h>
51 #include <visp3/core/vpMeterPixelConversion.h>
52 #include <visp3/core/vpPixelMeterConversion.h>
53 #include <visp3/core/vpMath.h>
54 #include <stdlib.h>
55 #include <stdio.h>
56 
57 int main()
58 {
59  try {
61  double px,py,u0,v0;
62  px = 1657.429131;
63  py = 1658.818598;
64  u0 = 322.2437833;
65  v0 = 230.8012737;
66  vpCameraParameters camDist;
67  double px_dist,py_dist,u0_dist,v0_dist,kud_dist,kdu_dist;
68  px_dist = 1624.824731;
69  py_dist = 1625.263641;
70  u0_dist = 324.0923411;
71  v0_dist = 245.2421388;
72  kud_dist = -0.1741532338;
73  kdu_dist = 0.1771165148;
74 
75  cam.initPersProjWithoutDistortion(px,py,u0,v0);
76  camDist.initPersProjWithDistortion(px_dist,py_dist,u0_dist,v0_dist,
77  kud_dist, kdu_dist);
78 
79  double u1 = 320;
80  double v1 = 240;
81  double x1 = 0, y1 = 0;
82  double u2 = 0, v2 = 0;
83  vpPixelMeterConversion::convertPoint(cam,u1,v1,x1,y1);
84  vpMeterPixelConversion::convertPoint(cam,x1,y1,u2,v2);
85  if(!vpMath::equal(u1,u2) || !vpMath::equal(v1,v2)){
86  vpTRACE("Error in convertPoint without distortion:\n"
87  "u1 = %f, u2 = %f\n"
88  "v1 = %f, v2 = %f\n",u1,u2,v1,v2);
89  return -1;
90  }
91  vpTRACE("convertPoint without distortion :\n"
92  "u1 - u2 = %.20f\n"
93  "v1 - v2 = %.20f\n",u1 - u2,v1 - v2);
94 
95  vpPixelMeterConversion::convertPoint(camDist,u1,v1,x1,y1);
96  vpMeterPixelConversion::convertPoint(camDist,x1,y1,u2,v2);
97  if(!vpMath::equal(u1,u2) || !vpMath::equal(v1,v2)){
98  vpTRACE("Error in convertPoint with distortion :\n"
99  "u1 = %f, u2 = %f\n"
100  "v1 = %f, v2 = %f\n",u1,u2,v1,v2);
101  return -1;
102  }
103  vpTRACE("convertPoint with distortion :\n"
104  "u1 - u2 = %.20f\n"
105  "v1 - v2 = %.20f\n",u1 - u2,v1 - v2);
106  return 0;
107  }
108  catch(vpException &e) {
109  std::cout << "Catch an exception: " << e << std::endl;
110  return 1;
111  }
112 }
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
static bool equal(double x, double y, double s=0.001)
Definition: vpMath.h:306
error that can be emited by ViSP classes.
Definition: vpException.h:73
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
#define vpTRACE
Definition: vpDebug.h:414
Generic class defining intrinsic camera parameters.
void initPersProjWithDistortion(const double px, const double py, const double u0, const double v0, const double kud, const double kdu)