Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GenGroundTruth.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __GENERATE_GROUND_TRUTH_HH__
27 #define __GENERATE_GROUND_TRUTH_HH__
28 
29 #include <Base/Common/BIASpragmaStart.hh>
30 
31 #include <Geometry/PMatrix.hh>
32 #include <Base/Geometry/KMatrix.hh>
33 #include <Base/Geometry/HomgPoint2D.hh>
34 #include <Base/Geometry/HomgPoint3D.hh>
35 #include <Base/Image/Image.hh>
36 
37 #include <vector>
38 
39 namespace BIAS {
40 
41  class BIASUtils_EXPORT GenGroundTruth
42  {
43  public:
44  /** normalizes the matches by multiplying with K^-1
45  @author woelk 05 2003 */
46  static void NormalizeMatches(std::vector<BIAS::HomgPoint2D>& match1,
47  std::vector<BIAS::HomgPoint2D>& match2,
48  BIAS::KMatrix K);
49 
50  /** de-normalizes the matches by multiplying with K
51  @author woelk 05 2003 */
52  static void DeNormalizeMatches(std::vector<BIAS::HomgPoint2D>& match1,
53  std::vector<BIAS::HomgPoint2D>& match2,
54  BIAS::KMatrix K);
55 
56  /** draws the matches in image im with background 0, match in color mcolor
57  and line defined by match in color lcolcor
58  @authior woelk 05 2003 */
59  static void DrawMatches(BIAS::Image<unsigned char>& im,
60  std::vector<BIAS::HomgPoint2D>& match1,
61  std::vector<BIAS::HomgPoint2D>& match2,
62  unsigned char lcolor, unsigned char mcolor);
63 
64  /** Generates ideal matches in cameras from pvec by randomly creating
65  a 3D point in the cube between min[x,y,z] and max[x,y,z] and
66  than looking if it projects into all cameras
67  @author woelk 05 2003 */
68  static void CreateIdealMatches(std::vector<BIAS::PMatrix>& pvec, unsigned num,
69  unsigned width, unsigned height,
70  std::vector<std::vector<BIAS::HomgPoint2D> >&
71  matches,
72  std::vector<BIAS::HomgPoint3D>& points,
73  double minx=-50.0, double maxx=50.0,
74  double miny=-50.0, double maxy=50.0,
75  double minz=-50.0, double maxz=50.0);
76 
77  /** Generates ideal matches in cameras from pvec by randomly creating
78  a 3D point in the cube between min[x,y,z] and max[x,y,z] and
79  than looking if it projects into all cameras
80  Adds spatial noise with sigma spatial_noise to position of 2D
81  points in every camera.
82  The ideal matches are returned in i_matches, the noisy matches are
83  returned in n_matches.
84  @author woelk 05 2003 */
85  static void CreateMatches(std::vector<BIAS::PMatrix>& pvec, unsigned num,
86  unsigned width, unsigned height, double spatial_noise,
87  std::vector<std::vector<BIAS::HomgPoint2D> >& i_matches,
88  std::vector<std::vector<BIAS::HomgPoint2D> >& n_matches,
89  std::vector<BIAS::HomgPoint3D>& points,
90  double minx=-50.0, double maxx=50.0,
91  double miny=-50.0, double maxy=50.0,
92  double minz=-50.0, double maxz=50.0);
93 
94  /** Generates ideal matches in cameras from pvec by randomly creating
95  a 3D point in the cube between min[x,y,z] and max[x,y,z] and
96  than looking if it projects into all cameras.
97  Adds spatial noise with a sigma of spatial_noise to position of 2D
98  points in every camera.
99  The ideal matches are returned in i_matches, the noisy matches are
100  returned in n_matches.
101  An additional normal ditributed position error with sigma of c_noise
102  and a normal distributed rotational error with sigma of r_noise are
103  assumed for the camera matrices.
104  The noisy camera matrices are returned in n_pvec.
105  @author woelk 05 2003 */
106  static void CreateMatches(std::vector<BIAS::PMatrix>& pvec,
107  std::vector<BIAS::PMatrix>& n_pvec, unsigned num,
108  unsigned width, unsigned height, double spatial_noise,
109  double r_noise, double c_noise,
110  std::vector<std::vector<BIAS::HomgPoint2D> >& i_matches,
111  std::vector<std::vector<BIAS::HomgPoint2D> >& n_matches,
112  std::vector<BIAS::HomgPoint3D>& points,
113  double minx=-50.0, double maxx=50.0,
114  double miny=-50.0, double maxy=50.0,
115  double minz=-50.0, double maxz=50.0, bool print=false);
116 
117  /** Generates ideal matches in cameras from pvec by randomly creating
118  a 3D point in the cube between min[x,y,z] and max[x,y,z] and
119  than looking if it projects into all cameras.
120  Adds spatial noise with a sigma of spatial_noise to position of 2D
121  points in every camera.
122  The ideal matches are returned in i_matches, the noisy matches are
123  returned in n_matches.
124  An additional normal ditributed position error with sigma of c_noise
125  and a normal distributed rotational error with sigma of r_noise are
126  assumed for the camera matrices.
127  The noisy camera matrices are returned in n_pvec.
128  outlier_fraction of the matches are outlier. They are generated by
129  adding a random offset to each x and y of each point after image 0.
130  The offset is generated between 2*spatial_noise and 10*spatial_noise.
131  @author woelk 05 2003 */
132  static void
133  CreateMatchesOutlier(std::vector<BIAS::PMatrix>& pvec,
134  std::vector<BIAS::PMatrix>& n_pvec, unsigned num,
135  unsigned width, unsigned height, double spatial_noise,
136  double r_noise, double c_noise, double outlier_fraction,
137  std::vector<std::vector<BIAS::HomgPoint2D> >& i_matches,
138  std::vector<std::vector<BIAS::HomgPoint2D> >& n_matches,
139  std::vector<BIAS::HomgPoint3D>& points,
140  double minx=-50.0, double maxx=50.0,
141  double miny=-50.0, double maxy=50.0,
142  double minz=-50.0, double maxz=50.0,
143  bool print=false);
144 
145  /** Generates 'n' points which are all located on a plane specified by
146  space point coords aX, aY, aZ and the coords of two spanning vectors
147  alphaX, alphaY, alphaZ and betaX, betaY, betaZ, which are normalized
148  internally.
149  'alphamax' and 'betamax' define width and height of the plane.
150  This method does not clear the result vector 'Points'!
151  By default it generates 200 points on a rectangular 100x100 plane in
152  the x-y-plane.
153  This method implicitly calls GenerateRandomCube with the third
154  dimension set to zero.
155  @author Matthias Dunda 08 2003 */
156  static void GenerateRandomPlane(std::vector<BIAS::HomgPoint3D> &Points,
157  int n=200,
158  double aX=-50.0, double aY=-50.0, double aZ=0.0,
159  double alphaX=1.0, double alphaY=0.0, double alphaZ=0.0,
160  double betaX=0.0, double betaY=1.0, double betaZ=0.0,
161  double alphamax=100.0,
162  double betamax=100.0);
163 
164  /** Generates 'n' points which are all located in a cube specified by
165  space point coords aX, aY, aZ and the coords of three spanning vectors
166  alphaX, alphaY, alphaZ and betaX, betaY, betaZ and
167  gammaX, gammaY, gammaZ, which are normalized internally.
168  'alphamax', 'betamax' and 'gammamax' define width, height and
169  depth of the cube.
170  This method does not clear the result vector 'Points'!
171  By default it generates 200 points on a rectangular 100x100x100 cube
172  centered at 0 0 0.
173  @author Matthias Dunda 08 2003 */
174  static void GenerateRandomCube(std::vector<BIAS::HomgPoint3D> &Points,
175  int n=200,
176  double aX=-50.0, double aY=-50.0, double aZ=-50.0,
177  double alphaX=1.0, double alphaY=0.0, double alphaZ=0.0,
178  double betaX=0.0, double betaY=1.0, double betaZ=0.0,
179  double gammaX=0.0, double gammaY=0.0, double gammaZ=1.0,
180  double alphamax=100.0,
181  double betamax=100.0,
182  double gammamax=100.0);
183 
184  static int ReadCorrespondences(const char *Filename,
185  std::vector<BIAS::HomgPoint2D> &Points1,
186  std::vector<BIAS::HomgPoint2D> &Points2);
187 
188  /** Store 2D picture correspondences in a file in binary format, so that
189  you can keep the full accuracy of a double.
190  @status tested
191  @author mdunda */
192  static int WriteCorrespondences(const char *Filename,
193  std::vector<BIAS::HomgPoint2D> &Points1,
194  std::vector<BIAS::HomgPoint2D> &Points2);
195 
196  /** Read 3D world coordinates from a file in binary format.
197  @status tested
198  @author mdunda */
199  static int ReadWorldPoints( const char *Filename,
200  std::vector<BIAS::HomgPoint3D> & Points );
201 
202  /** Store 3D world coordinates in a file in binary format, so that
203  you can keep the full accuracy of a double.
204  @status tested
205  @author mdunda */
206  static int WriteWorldPoints( const char *Filename,
207  std::vector<BIAS::HomgPoint3D> & Points );
208 
209  }; /* class GenGroundTruth */
210 
211 } /* namespace MIP */
212 
213 #include <Base/Common/BIASpragmaEnd.hh>
214 
215 #endif /* __GENERATE_GROUND_TRUTH_HH__ */
216 
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48