Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleTransformToCartesian.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 /**
27  @example ExampleTransformToCartesian.cpp
28  @relates ProjectionParametersPerspective
29  @brief small example demonstrating the TransformToCartesian Function
30  @ingroup g_examples
31  @author ischiller 06/2010
32 */
33 
34 #include <Geometry/Projection.hh>
35 #include <Geometry/ProjectionParametersPerspective.hh>
36 #include <Base/Image/Image.hh>
37 #include <Base/Image/ImageIO.hh>
38 #include <Utils/Param.hh>
39 #include <Utils/IOUtils.hh>
40 
41 using namespace BIAS;
42 using namespace std;
43 
44 
45 int main(int argc, char *argv[])
46 {
47 
48  Param params;
49  string *proj = params.AddParamString("Projection","The projection to use, not mandatory","", 'p');
50  string *image = params.AddParamString("Image","The float (depth) image to use, not mandatory","", 'i');
51 
52  if (!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
53  { return 0; }
54 
55  Projection projection;
56 
57  int ret = 0;
58 
59  if(*proj!=""){
60  ret = projection.XMLRead(*proj);
61  cout<<"Loaded projection:"<<*proj<<endl;
62  }
63  if(string(*proj)=="" || ret < 0){
65  ppp.SetSimplePerspective(40,176,144); //typical PMD camera
66  ppp.SetFocalLengthAndAspect(250.0,1.0);
67  ppp.ValidatePose();
68  projection.AddAbsoluteCamera(&ppp);
69  cout<<"Generated sample projection."<<endl;
70  }
71 
72  Image<float> depthImg,cartDepthImg,polarDepthImg;
73  if(*image !=""){
74  ret = ImageIO::Load(*image,polarDepthImg );
75  cout<<"Loaded image :"<<*image<<endl;
76  }
77  if(string(*image)=="" || ret < 0){
78  depthImg.Init(176,144,1);
79  depthImg.FillImageWithConstValue(2000.0);
80  cout<<"Filled standard image with 5000mm.";
81 
82  if((dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))!= NULL){
83  (dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
84  TransformCartesianToPolarCoordinates(depthImg, polarDepthImg);
85  }
86  cout<<" ..and transformed to polar."<<endl;
87  }
88 
89  ImageIO::Save("polarInput.mip",polarDepthImg);
90 
91  if((dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))!= NULL){
92  (dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
93  TransformPolarToCartesianCoordinates(polarDepthImg, cartDepthImg);
94  ImageIO::Save("cartesianOutput.mip",cartDepthImg);
95  (dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
96  TransformCartesianToPolarCoordinates(cartDepthImg,polarDepthImg);
97  ImageIO::Save("polarOutput.mip",polarDepthImg);
98 
99  cout<<"Transformed Images."<<endl;
100  }
101  else {
102  BIASERR("Not a perspective camera");
103  return -1;
104  }
105 
106  return 0;
107 }
int XMLRead(const std::string &Filename)
derived classes must implement the function XMLIn which is called by this function XMLRead to read ev...
Definition: XMLBase.cpp:78
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
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
void FillImageWithConstValue(StorageType Value)
fill grey images
Definition: Image.cpp:456
static bool ParseCommandLineEvalHelp(Param &params, int argc, char *argv[])
parses the command line, adds parameter &quot;help&quot;
Definition: IOUtils.cpp:176
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
void AddAbsoluteCamera(ProjectionParametersBase *ppb)
Add a camera to the projection,the coordinates of the pose are given in absolute Coordinates, they are transformed to relative coordinates to the first camera internally.
Definition: Projection.cpp:199
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
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
virtual void ValidatePose()
Validate currently set pose.
void SetFocalLengthAndAspect(double f, double AspectRatio)
Set the current camera focal length in pixel and the a spect ratio.
void SetSimplePerspective(const double FoV=M_PI/2, const unsigned int width=512, const unsigned int height=512)
Sets the parameters for a simple perspective camera with imagesize 512x512, focal length 512 (fov = 9...
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