ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
testCameraParametersConversion.cpp
1 /****************************************************************************
2  *
3  * $Id: testCameraParametersConversion.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  * Performs various tests on the vpPixelMeterConversion and
36  * vpPixelMeterConversion class.
37  *
38  * Authors:
39  * Anthony saunier
40  *
41  *****************************************************************************/
42 
43 
44 
52 // List of allowed command line options
53 #define GETOPTARGS "h"
54 
55 #include <visp/vpMath.h>
56 #include <visp/vpDebug.h>
57 #include <visp/vpParseArgv.h>
58 #include <visp/vpCameraParameters.h>
59 #include <visp/vpMeterPixelConversion.h>
60 #include <visp/vpPixelMeterConversion.h>
61 #include <visp/vpMath.h>
62 #include <stdlib.h>
63 #include <stdio.h>
64 
70 void usage(const char *name, const char *badparam)
71 {
72  fprintf(stdout, "\n\
73  Performs various tests on the vpPixelMeterConversion and\n\
74  vpPixelMeterConversion class.\n\
75 \n\
76 SYNOPSIS\n\
77  %s [-h]\n", name);
78 
79  fprintf(stdout, "\n\
80 OPTIONS: Default\n\
81  -h\n\
82  Print the help.\n");
83 
84  if (badparam)
85  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
86 }
94 bool getOptions(int argc, const char **argv)
95 {
96  const char *optarg;
97  int c;
98  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
99 
100  switch (c) {
101  case 'h': usage(argv[0], NULL); return false; break;
102 
103  default:
104  usage(argv[0], optarg);
105  return false; break;
106  }
107  }
108 
109  if ((c == 1) || (c == -1)) {
110  // standalone param or error
111  usage(argv[0], NULL);
112  std::cerr << "ERROR: " << std::endl;
113  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
114  return false;
115  }
116 
117  return true;
118 }
119 
120 
121 int
122 main(int argc, const char ** argv)
123 {
124  // Read the command line options
125  if (getOptions(argc, argv) == false) {
126  exit (-1);
127  }
128 
129  vpCameraParameters cam;
130  double px,py,u0,v0;
131  px = 1657.429131;
132  py = 1658.818598;
133  u0 = 322.2437833;
134  v0 = 230.8012737;
135  vpCameraParameters camDist;
136  double px_dist,py_dist,u0_dist,v0_dist,kud_dist,kdu_dist;
137  px_dist = 1624.824731;
138  py_dist = 1625.263641;
139  u0_dist = 324.0923411;
140  v0_dist = 245.2421388;
141  kud_dist = -0.1741532338;
142  kdu_dist = 0.1771165148;
143 
144  cam.initPersProjWithoutDistortion(px,py,u0,v0);
145  camDist.initPersProjWithDistortion(px_dist,py_dist,u0_dist,v0_dist,
146  kud_dist, kdu_dist);
147 
148  double u1 = 320;
149  double v1 = 240;
150  double x1 = 0, y1 = 0;
151  double u2 = 0, v2 = 0;
152  vpPixelMeterConversion::convertPoint(cam,u1,v1,x1,y1);
153  vpMeterPixelConversion::convertPoint(cam,x1,y1,u2,v2);
154  if(!vpMath::equal(u1,u2) || !vpMath::equal(v1,v2)){
155  vpTRACE("Error in convertPoint without distortion:\n"
156  "u1 = %f, u2 = %f\n"
157  "v1 = %f, v2 = %f\n",u1,u2,v1,v2);
158  return -1;
159  }
160  vpTRACE("convertPoint without distortion :\n"
161  "u1 - u2 = %.20f\n"
162  "v1 - v2 = %.20f\n",u1 - u2,v1 - v2);
163 
164  vpPixelMeterConversion::convertPoint(camDist,u1,v1,x1,y1);
165  vpMeterPixelConversion::convertPoint(camDist,x1,y1,u2,v2);
166  if(!vpMath::equal(u1,u2) || !vpMath::equal(v1,v2)){
167  vpTRACE("Error in convertPoint with distortion :\n"
168  "u1 = %f, u2 = %f\n"
169  "v1 = %f, v2 = %f\n",u1,u2,v1,v2);
170  return -1;
171  }
172  vpTRACE("convertPoint with distortion :\n"
173  "u1 - u2 = %.20f\n"
174  "v1 - v2 = %.20f\n",u1 - u2,v1 - v2);
175  return 0;
176 }
#define vpTRACE
Definition: vpDebug.h:401
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:275
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...
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
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)