Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleXB3Rectification.cpp
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  * @example ExampleXB3Rectification.cpp
27  * @relates PlanarRectification, RectificationBase
28  * @brief shows rectification for PtGrey Bumblebee
29  * @author MIP
30  */
31 
32 #include <iostream>
33 #include <Base/Image/ImageIO.hh>
34 #include <Image/Camera.hh>
35 #include <Image/PlanarRectification.hh>
36 #include <Image/RectificationBase.hh>
37 #include <Utils/Param.hh>
38 #include <Utils/IOUtils.hh>
39 
40 using namespace std;
41 using namespace BIAS;
42 
43 
44 int main(int argc, char* argv[])
45 {
46  Param params(true);
47 
48  int IOGrpID = params.GetFreeGroupID();
49  string* leftCamName = params.AddParamString("leftCam", "",
50  "", 0, IOGrpID);
51  string* centerCamName = params.AddParamString("centerCam", "",
52  "", 0, IOGrpID);
53  string* rightCamName = params.AddParamString("rightCam", "",
54  "", 0, IOGrpID);
55  params.SetGroupName(IOGrpID, "I/O");
56 
57  if(!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
58  return 0;
59 
60  Camera<unsigned char> camLeft, camCenter, camRight;
61  Projection projLeft, projRight, projCenter;
62  if(!IOUtils::LoadCamera<unsigned char>(leftCamName, camLeft, projLeft))
63  return -1;
64  if(!IOUtils::LoadCamera<unsigned char>(centerCamName, camCenter, projCenter))
65  return -1;
66  if(!IOUtils::LoadCamera<unsigned char>(rightCamName, camRight, projRight))
67  return -1;
68 
69 
70 
71  Pose poseLeft = projLeft.GetPose();
72  Pose poseRight = projRight.GetPose();
73  Pose poseCenter = projCenter.GetPose();
74  Quaternion<double> orientation;
75 
76  ProjectionParametersPerspective rectPPPLeft, rectPPPRight, rectPPPCenter;
79  poseCenter,
80  poseRight,
81  orientation);
82 
83  CoordinateTransform3D sphericalBase; // will contain the canonical
84  // sphericalBase.Set(poseCenter.GetQ(), poseCenter.GetC());
85  sphericalBase.Set(orientation, poseCenter.GetC());
86  // (cartesian) base
87  Quaternion<double> rot(0, -sin(M_PI/4.0), 0, cos(M_PI/4.0));
88  sphericalBase.RotateLocalFrame(rot);
89  double minPhi, maxPhi, centerPhi, minTheta, maxTheta;
90  cerr<<"sphericalBase "<<sphericalBase.GetR()<<endl;
91  cerr<<"CameraBase "<<projCenter.GetR()<<endl;
92  projCenter.GetParameters()->GetSphericalViewingRange(sphericalBase,
93  minPhi, maxPhi,
94  centerPhi,
95  minTheta, maxTheta );
96  cerr<<"minPhi "<<minPhi<<", maxPhi "<<maxPhi<<endl;
97  cerr<<"centerPhi "<<centerPhi<<endl;
98  cerr<<"minTheta "<<minTheta<<", maxTheta "<<maxTheta<<endl;
99 
100  double minSamplingStep;
101  projCenter.GetParameters()->GetMinimalAngularSamplingStep(minSamplingStep);
102 
103  //controlls cut out !
104  minPhi+= 2.0*0.06;
105  maxPhi-= 5.0*0.06;
106  minTheta+= 0.06;
107  maxTheta-= 5.0*0.06;
108 
109  rectPPPCenter.SetIntrinsics(minPhi, maxPhi,
110  minTheta, maxTheta,
111  2.0*minSamplingStep);
112 
113 
114  rectPPPLeft=rectPPPRight=rectPPPCenter;
115 
116  rectPPPLeft.SetC(poseLeft.GetC());
117  rectPPPLeft.SetQ(orientation);
118  rectPPPCenter.SetC(poseCenter.GetC());
119  rectPPPCenter.SetQ(orientation);
120  rectPPPRight.SetC(poseRight.GetC());
121  rectPPPRight.SetQ(orientation);
122  cerr<<"rectPPPC = "<<rectPPPCenter<<endl;
123  cerr<<"rectPPPLeft = "<<rectPPPLeft<<endl;
124  cerr<<"rectPPPRight = "<<rectPPPRight<<endl;
125 
127  rectifierCenter, rectifierRight;
128 
129  unsigned int targetWidth, targetHeight;
130  rectPPPCenter.GetImageSize(targetWidth, targetHeight);
131  cerr<<targetWidth<<"x"<< targetHeight<<endl;
132 
133  Camera<unsigned char> rectCamLeft, rectCamRight, rectCamCenter;
134  rectCamLeft.Init(targetWidth, targetHeight,3);
135  rectCamRight.Init(targetWidth, targetHeight,3);
136  rectCamCenter.Init(targetWidth, targetHeight,3);
137 
138 
139  rectifierCenter.SetSourceCam(projCenter);
140  rectifierCenter.SetSinkCam(Projection(rectPPPCenter));
141  rectifierCenter.PrepareLookupTableMapping(camCenter, rectCamCenter,
142  MapBilinear);
143 
144  rectifierLeft.SetSourceCam(projLeft);
145  rectifierLeft.SetSinkCam(Projection(rectPPPLeft));
146  rectifierLeft.PrepareLookupTableMapping(camLeft, rectCamLeft,
147  MapBilinear);
148 
149  rectifierLeft.SetSourceCam(projRight);
150  rectifierLeft.SetSinkCam(Projection(rectPPPRight));
151  rectifierLeft.PrepareLookupTableMapping(camRight, rectCamRight,
152  MapBilinear);
153 
154  rectifierCenter.Map(camCenter, rectCamCenter);
155  IOUtils::SaveCamera<unsigned char>("centerRect.mip",
156  rectCamCenter,
157  Projection(rectPPPCenter));
158  rectifierCenter.Map(camLeft, rectCamLeft);
159  IOUtils::SaveCamera<unsigned char>("leftRect.mip",
160  rectCamLeft,
161  Projection(rectPPPLeft));
162 
163  rectifierCenter.Map(camRight, rectCamRight);
164  IOUtils::SaveCamera<unsigned char>("righRect.mip",
165  rectCamRight,
166  Projection(rectPPPRight));
167 
168 
169  return 0;
170 }
171 
172 
173 
174 
175 
BIAS::RMatrixBase GetR() const
Get orientation of local coordinate system as rotation matrix mapping from local coordinates to globa...
int SetIntrinsics(double minPhi, double maxPhi, double minTheta, double maxTheta, double angleStep, double aspectratio=1.0)
Method calculates K-Matrix and image size from specified angles.
virtual void Set(const Quaternion< double > &Q, const Vector3< double > &C, const double &scale=1.0)
Define local coordinate frame from within the world frame.
virtual const Pose & GetPose(unsigned int cam=0) const
return complete pose object.
Definition: Projection.hh:318
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
void SetSinkCam(const Projection &P, const Image< float > *sinkdepth=NULL)
Set your sink projection before calling Map(),.
const Vector3< double > & GetC() const
Set origin of local coordinate system in global coordinates.
void SetSourceCam(const Projection &P)
Set your source projection before calling Map()
void RotateLocalFrame(const Quaternion< double > &Q)
Applies the passed rotation to the orientation of the local frame.
virtual int GetSphericalViewingRange(const CoordinateTransform3D &sphericalReferenceFrame, double &minPhi, double &maxPhi, double &centerPhi, double &minTheta, double &maxTheta)
Determines the maximal and minimal viewing range in means of spherical coordinates.
base class for rectification implementations and wrappers
virtual void SetQ(const BIAS::Quaternion< double > &Q)
Set orientation from unit quaternion Q.
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
Definition: Projection.hh:194
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
int Map(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod=MapTrilinear, bool newSink=false, double SuperSampling=1.0)
backward mapping with various interpolations
int GetFreeGroupID()
returns unused group id
Definition: Param.cpp:1421
int PrepareLookupTableMapping(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod method, bool newSink=false)
precomputes lookup coordinates for accessing src
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
This class Param provides generic support for parameters.
Definition: Param.hh:231
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
Definition: Param.cpp:1448
Transforms 3d points between two different coodinate systems, e.g.
virtual int GetMinimalAngularSamplingStep(double &minAngleStep)
Delivers the assumed minimal angular distance between two optical rays belonging to integer image coo...
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327
virtual void SetC(const BIAS::Vector3< double > &C)
Set projection center.
RMatrix GetR(unsigned int cam=0) const
return RMatrix of camera with index cam.
Definition: Projection.hh:243