Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestProjectionParametersOrthographic.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21 
22 
23 /**
24  @file TestProjectionParametersOrthographic.cpp
25  @brief Unit test for basic functionality of projection parameters orthographic.
26  @relates ProjectionParametersOrthographic
27  @ingroup g_tests
28  @author MIP
29 */
30 
31 
32 #include <Base/Common/CompareFloatingPoint.hh>
33 
34 #include <Geometry/ProjectionParametersOrthographic.hh>
35 #include <Base/Math/Random.hh>
36 #include <string>
37 #include <vector>
38 
39 
40 using namespace BIAS;
41 using namespace std;
43 
44 #define EPSILON 1e-8
45 
46 
47 int main(int argc, char *argv[]){
48  const unsigned int width = 800;
49  const unsigned int height = 600;
50  Vector3<double> rayDir(0, 0, 1);
51  double dX = 1;
52  double dY = 1;
53  PPO ppo(rayDir, width, height, dX, dY);
54  ppo.SetPrincipal(561.5692167, 348.5405689);
55 
56  Quaternion<double> Q(0,0,0,1);
57  ppo.SetQ(Q);
58  Vector3<double> C(0,0,0);
59  ppo.SetC(C);
60 
61  Random rand;
62  int percent = -1;
63 
64  int countError = 0;
65  int countAll = 0;
66  double sumError = 0.0;
67  double sumSqError = 0.0;
68 
69  unsigned int numCams = 100; //1000
70  unsigned int numPoints = 100; //1000
71 
72  HomgPoint2D p2d;
73  HomgPoint2D p2d_p;
74  HomgPoint3D p3d;
75  double maxError = 0.0;
76  double dist = 0;
77  double error = 0;
78 
79  for(unsigned int cams=0; cams < numCams; cams++){
80  ppo.SetPrincipal(rand.GetUniformDistributed(100, 700),
81  rand.GetUniformDistributed(100, 500));
82  for(unsigned int points=0; points < numPoints; points++){
83  if(points == 0){
84  // use origin as first 2d point
85  p2d[0] = p2d[1] = 0.0;
86  p2d[2] = 1.0;
87  dist = 5000.0;
88  }else{
89  // generate random 2d point and depth
90  p2d[0] = rand.GetUniformDistributed(10, width-11);
91  p2d[1] = rand.GetUniformDistributed(10, height-11);
92  p2d[2] = 1.0;
93  dist = rand.GetUniformDistributed(100.0, 5000.0);
94  }
95 
96  p3d = ppo.UnProjectToPoint(p2d, dist, true);
97  p2d_p = ppo.Project(p3d, true);
98  error = (p2d_p.GetEuclidean()-p2d.GetEuclidean()).NormL2();
99  cout<<"point: "<<p2d<<" proj_point: "<<p2d_p<<" error: "<<error<<endl;
100  if(Greater(error, EPSILON)){
101  countError++;
102  }
103  if(maxError < error){
104  maxError = error;
105  }
106  sumError += error;
107  sumSqError += error*error;
108  countAll++;
109  }
110 
111  // show progress
112  int pr = int(100.0*double(cams)/numCams);
113  if(percent < pr){
114  while(percent < pr) {
115  cout<<".";
116  percent++;
117  }
118  cout<<" "<<percent<<"% ";
119  }
120  }
121 
122  double meanError = sumError / (double)countAll;
123  double stdError = sqrt(sumSqError / (double)countAll - meanError*meanError);
124 
125  cout<<"\n\n----------------------------------------------------------\n"
126  <<" count of errors > "<<EPSILON<<" : "<<countError
127  <<" ("<<100.0*(double)countError/(double)countAll<<"%)\n"
128  <<" average error : "<<meanError<<" +- "<<stdError<<endl
129  <<" max. error : "<<maxError<<endl
130  <<"----------------------------------------------------------\n\n";
131 
132  return 0;
133 }
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
void GetEuclidean(Vector2< HOMGPOINT2D_TYPE > &dest) const
calculate affine coordinates of this and write them to dest affine coordinates are projective coordin...
Definition: HomgPoint2D.hh:244
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Definition: Random.hh:84
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
bool Greater(const T left, const T right, const T eps=std::numeric_limits< T >::epsilon())
comparison function for floating point values
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
class for producing random numbers from different distributions
Definition: Random.hh:51