ViSP  2.9.0
testCameraParametersConversion.cpp
1 /****************************************************************************
2  *
3  * $Id: testCameraParametersConversion.cpp 4658 2014-02-09 09:50:14Z 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  * 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 
65 void usage(const char *name, const char *badparam);
66 bool getOptions(int argc, const char **argv);
67 
73 void usage(const char *name, const char *badparam)
74 {
75  fprintf(stdout, "\n\
76  Performs various tests on the vpPixelMeterConversion and\n\
77  vpPixelMeterConversion class.\n\
78 \n\
79 SYNOPSIS\n\
80  %s [-h]\n", name);
81 
82  fprintf(stdout, "\n\
83 OPTIONS: Default\n\
84  -h\n\
85  Print the help.\n");
86 
87  if (badparam)
88  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
89 }
97 bool getOptions(int argc, const char **argv)
98 {
99  const char *optarg_;
100  int c;
101  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
102 
103  switch (c) {
104  case 'h': usage(argv[0], NULL); return false; break;
105 
106  default:
107  usage(argv[0], optarg_);
108  return false; break;
109  }
110  }
111 
112  if ((c == 1) || (c == -1)) {
113  // standalone param or error
114  usage(argv[0], NULL);
115  std::cerr << "ERROR: " << std::endl;
116  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
117  return false;
118  }
119 
120  return true;
121 }
122 
123 
124 int
125 main(int argc, const char ** argv)
126 {
127  try {
128  // Read the command line options
129  if (getOptions(argc, argv) == false) {
130  exit (-1);
131  }
132 
133  vpCameraParameters cam;
134  double px,py,u0,v0;
135  px = 1657.429131;
136  py = 1658.818598;
137  u0 = 322.2437833;
138  v0 = 230.8012737;
139  vpCameraParameters camDist;
140  double px_dist,py_dist,u0_dist,v0_dist,kud_dist,kdu_dist;
141  px_dist = 1624.824731;
142  py_dist = 1625.263641;
143  u0_dist = 324.0923411;
144  v0_dist = 245.2421388;
145  kud_dist = -0.1741532338;
146  kdu_dist = 0.1771165148;
147 
148  cam.initPersProjWithoutDistortion(px,py,u0,v0);
149  camDist.initPersProjWithDistortion(px_dist,py_dist,u0_dist,v0_dist,
150  kud_dist, kdu_dist);
151 
152  double u1 = 320;
153  double v1 = 240;
154  double x1 = 0, y1 = 0;
155  double u2 = 0, v2 = 0;
156  vpPixelMeterConversion::convertPoint(cam,u1,v1,x1,y1);
157  vpMeterPixelConversion::convertPoint(cam,x1,y1,u2,v2);
158  if(!vpMath::equal(u1,u2) || !vpMath::equal(v1,v2)){
159  vpTRACE("Error in convertPoint without distortion:\n"
160  "u1 = %f, u2 = %f\n"
161  "v1 = %f, v2 = %f\n",u1,u2,v1,v2);
162  return -1;
163  }
164  vpTRACE("convertPoint without distortion :\n"
165  "u1 - u2 = %.20f\n"
166  "v1 - v2 = %.20f\n",u1 - u2,v1 - v2);
167 
168  vpPixelMeterConversion::convertPoint(camDist,u1,v1,x1,y1);
169  vpMeterPixelConversion::convertPoint(camDist,x1,y1,u2,v2);
170  if(!vpMath::equal(u1,u2) || !vpMath::equal(v1,v2)){
171  vpTRACE("Error in convertPoint with distortion :\n"
172  "u1 = %f, u2 = %f\n"
173  "v1 = %f, v2 = %f\n",u1,u2,v1,v2);
174  return -1;
175  }
176  vpTRACE("convertPoint with distortion :\n"
177  "u1 - u2 = %.20f\n"
178  "v1 - v2 = %.20f\n",u1 - u2,v1 - v2);
179  return 0;
180  }
181  catch(vpException e) {
182  std::cout << "Catch an exception: " << e << std::endl;
183  return 1;
184  }
185 }
#define vpTRACE
Definition: vpDebug.h:418
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
error that can be emited by ViSP classes.
Definition: vpException.h:76
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)