Visual Servoing Platform  version 3.1.0
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 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  * Performs various tests on the vpPixelMeterConversion and
33  * vpPixelMeterConversion class.
34  *
35  * Authors:
36  * Anthony saunier
37  *
38  *****************************************************************************/
39 
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <visp3/core/vpCameraParameters.h>
50 #include <visp3/core/vpDebug.h>
51 #include <visp3/core/vpMath.h>
52 #include <visp3/core/vpMeterPixelConversion.h>
53 #include <visp3/core/vpPixelMeterConversion.h>
54 
55 int main()
56 {
57  try {
59  double px, py, u0, v0;
60  px = 1657.429131;
61  py = 1658.818598;
62  u0 = 322.2437833;
63  v0 = 230.8012737;
64  vpCameraParameters camDist;
65  double px_dist, py_dist, u0_dist, v0_dist, kud_dist, kdu_dist;
66  px_dist = 1624.824731;
67  py_dist = 1625.263641;
68  u0_dist = 324.0923411;
69  v0_dist = 245.2421388;
70  kud_dist = -0.1741532338;
71  kdu_dist = 0.1771165148;
72 
73  cam.initPersProjWithoutDistortion(px, py, u0, v0);
74  camDist.initPersProjWithDistortion(px_dist, py_dist, u0_dist, v0_dist, kud_dist, kdu_dist);
75 
76  double u1 = 320;
77  double v1 = 240;
78  double x1 = 0, y1 = 0;
79  double u2 = 0, v2 = 0;
80  vpPixelMeterConversion::convertPoint(cam, u1, v1, x1, y1);
81  vpMeterPixelConversion::convertPoint(cam, x1, y1, u2, v2);
82  if (!vpMath::equal(u1, u2) || !vpMath::equal(v1, v2)) {
83  vpTRACE("Error in convertPoint without distortion:\n"
84  "u1 = %f, u2 = %f\n"
85  "v1 = %f, v2 = %f\n",
86  u1, u2, v1, v2);
87  return -1;
88  }
89  vpTRACE("convertPoint without distortion :\n"
90  "u1 - u2 = %.20f\n"
91  "v1 - v2 = %.20f\n",
92  u1 - u2, v1 - v2);
93 
94  vpPixelMeterConversion::convertPoint(camDist, u1, v1, x1, y1);
95  vpMeterPixelConversion::convertPoint(camDist, x1, y1, u2, v2);
96  if (!vpMath::equal(u1, u2) || !vpMath::equal(v1, v2)) {
97  vpTRACE("Error in convertPoint with distortion :\n"
98  "u1 = %f, u2 = %f\n"
99  "v1 = %f, v2 = %f\n",
100  u1, u2, v1, v2);
101  return -1;
102  }
103  vpTRACE("convertPoint with distortion :\n"
104  "u1 - u2 = %.20f\n"
105  "v1 - v2 = %.20f\n",
106  u1 - u2, v1 - v2);
107  return 0;
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:290
error that can be emited by ViSP classes.
Definition: vpException.h:71
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:416
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)