Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RectificationBase.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 #ifndef __RectificationBase_hh__
26 #define __RectificationBase_hh__
27 
28 #include <Image/Camera.hh>
29 #include <Base/Image/Image.hh>
30 #include <Geometry/ProjectionParametersBase.hh>
31 
32 namespace BIAS {
33 
34 #define UNDEFINED_DEPTH 0.0
35 
36  /**
37  * base class for rectification implementations and wrappers
38  * \ingroup Stereo
39  * \ingroup g_filter
40  * \author bartczak 11/2006
41  */
42  template <class InputStorageType, class OutputStorageType>
43  class BIASImage_EXPORT RectificationBase {
44  public:
45 
46  virtual ~RectificationBase();
48 
49  /** \name Input data
50  * fundamental setters.*/
51  /** @{*/
52  /** \returns -1 if rectification class is not supporting the
53  * specified projection type (what includes invalid projections).
54  * \returns 1 if argument projection is already set.
55  */
56  virtual int SetCameraA(BIAS::Camera<InputStorageType>& cam);
57 
58  /** \returns -1 if rectification class is not supporting the
59  * specified projection type (what includes invalid projections).
60  * \returns 1 if argument projection is already set.
61  * Will only use pointer for polymorphism.
62  * Will aquire copy of projection.
63  */
64  virtual int SetCameraA(const BIAS::Image<InputStorageType>& img,
65  const BIAS::ProjectionParametersBase* proj);
66 
67  /** \returns -1 if rectification class is not supporting the
68  * specified projection type (what includes invalid projections).
69  * \returns 1 if argument projection is already set.
70  */
71  virtual int SetCameraB(BIAS::Camera<InputStorageType>& cam);
72 
73  /** \returns -1 if rectification class is not supporting the
74  * specified projection type (what includes invalid projections).
75  * \returns 1 if argument projection is already set.
76  * Will only use pointer for polymorphism.
77  * Will aquire copy of projection.
78  */
79  virtual int SetCameraB(const BIAS::Image<InputStorageType>& img,
80  const BIAS::ProjectionParametersBase* proj);
81  /** @}*/
82 
83  /** Fundamental method which contains the rectification implementation.
84  * \returns 0 on successfull rectification.
85  */
86  virtual int Rectify() = 0;
87 
88  /** Uses the passed disparity map for camera A to calculate the
89  * corresponding depth map.
90  * \param DisparityMap disparity map for camera A.
91  * \param DepthMap resulting depth map for camera A.
92  * \param border image border of depth map that will be ignored
93  */
94  virtual int Disp2Depth(const Image<float>& DisparityMap,
95  Image<float>& DepthMap,
96  unsigned int border) = 0;
97 
98  /** \name Getters
99  * Return stored results. If there are.
100  */
101  //@{
102  void GetRectifiedImageA(Image<OutputStorageType>& rectImg);
103  void GetRectifiedImageB(Image<OutputStorageType>& rectImg);
104  //@}
105 
106  /** \name Utility functions
107  * Methods connected with rectification but are rather unspecific.
108  */
109  //@{
110  /** Method determines two orthonormal bases suitable for rectification.
111  * This bases are parallel to oneanother. The x-basevector is parallel to
112  * the line connecting the origins of poseA and poseB. The z-basevector
113  * is chosen so that it is in between the z-vectors of original poses.
114  * \param failIfForwardMove if true will have an error code(<0) returned
115  * if one of the original z-basevectors is parallel to baseline
116  */
117  static int CalculateRectifiedBases(const Pose& poseA,
118  const Pose& poseB,
119  Pose& poseResA,
120  Pose& poseResB,
121  bool failIfForwardMove = false);
122  /** Method calculates an intermediate orientation for rectification
123  * from all three poses. Does not check for forward movement now!
124  * Fails if two of the cameras are the same!
125  */
126  static int CalculateMeanOrientation(const Pose& poseLeft,
127  const Pose& poseCenter,
128  const Pose& poseRight,
129  Quaternion<double>& orientation);
130  //@}
131 
132  /** @{
133  * Method is called by SetCamera* methods and returns true if arguments
134  * are accepted by rectification implementations. E.g. a rectification
135  * method specialised on perspective images will refuse to handle
136  * spherical parameters. If method returns false the SetCamera* routines
137  * will also fail.
138  */
139  /** Method calls two parameteric pure virtual method */
140  bool IsInputCameraValid(BIAS::Camera<InputStorageType>& cam);
141 
142 
143  /** \name Grabbing/RT Utils
144  * Methods granting direct access to data structures of rectification.
145  * \attention Use this with caution, methods were introduced to allow
146  * direct image grabbing into rectification object and efficient
147  * rectification readout when camera parameter do not change!
148  * \attention Use of methods belonging to this group does not trigger ANY
149  * state update!
150  * Methods were designed for following scenario:
151  * -# Use Set methods to initialize rectification and trigger state update.
152  * -# Use pointer aquired by GetImagePointerA()/B() to set original image
153  * content! It is not possible to set the ProjectionParamters this way!
154  * -# Call Rectify(): running this the first time will take some
155  * calculational effort because LUT will be constructed.
156  * -# Use pointer aquired GetRectifiedImagePointerA()/B(): to readout
157  * the result.
158  * If camera parameters do not change repeat all but the first dash to
159  * aquire rectified images.
160  */
161  //@{
162  Camera<InputStorageType>* GetImagePointerA();
163  Camera<InputStorageType>* GetImagePointerB();
164  const Image<OutputStorageType>* GetRectifiedImagePointerA();
165  const Image<OutputStorageType>* GetRectifiedImagePointerB();
166  //@}
167 
168  virtual bool
169  IsInputCameraValid(const BIAS::Image<InputStorageType>& img,
170  const BIAS::ProjectionParametersBase* proj) = 0;
171  /** @} */
172  protected:
173 
174  /** local copy of passed projection parameters*/
176 
177  /** local copy of passed image*/
179 
180  /** local copy of passed projection parameters*/
182 
183  /** local copy of passed image*/
185 
186  /** Results of rectification */
188 
189  /** Results of rectification */
191 
192 
193  };
194 
195 
196 }//end of namespace
197 
198 #endif
199 
ProjectionParametersBase * ppBA_
local copy of passed projection parameters
base class for rectification implementations and wrappers
ProjectionParametersBase * ppBB_
local copy of passed projection parameters
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
Image< OutputStorageType > rectImageA_
Results of rectification.
Image< OutputStorageType > rectImageB_
Results of rectification.
Camera< InputStorageType > imageB_
local copy of passed image
Camera< InputStorageType > imageA_
local copy of passed image
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...