Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCylinderMapping.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 ExampleCylinderMapping.cpp
27  @relates CylinderMapping
28  @brief Example for mapping an image with BIAS::CylinderMapping
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <string>
34 #include <iostream>
35 
36 // bias includes
37 #include <Utils/Param.hh>
38 #include <Base/Image/ImageIO.hh>
39 #include <Image/CylinderMapping.hh>
40 #include <Base/Debug/TimeMeasure.hh>
41 
42 using namespace BIAS;
43 using namespace std;
44 
45 int main(int args, char **arg)
46 {
47  // initialize parameters
48  BIAS::Param param;
49 
50  param.DisableDestructorWarning(); // no warning at exit
51 
52  // add parameterss (as unclassified parameter group)
53  param.AddParamBool("help","prints info about all parameters", false, 'h');
54  param.AddParamString("image", "image file to load", "", 'i');
55  param.AddParamDouble("focal", "focal length", 100.0, -1, 1e6,'f');
56  param.AddParamDouble("hx", "principal point x", -1, -1, 1e6);
57  param.AddParamDouble("hy", "principal point y", -1, -1, 1e6);
58  std::vector<int> vecMethodIDs;
59  std::vector<string> vecMethodNames;
60  vecMethodIDs.push_back((int)MapBilinear);
61  vecMethodNames.push_back("bi");
62  vecMethodIDs.push_back((int)MapTrilinear);
63  vecMethodNames.push_back("tri");
64  param.AddParamEnum("method", "interpolation method (bi, tri)",
65  vecMethodNames, (int)MapTrilinear, &vecMethodIDs, 'm');
66 
67  // get command line parameters
68  param.ParseCommandLine(args, arg);
69 
70  // print help information
71  if ( *param.GetParamBool("help") == true ) {
72  cout << endl;
73  param.Usage();
74  exit(0);
75  }
76 
77  // show image if given
78  if ( param.GetParamString("image")->empty() ) {
79  cout << "no input image specified (try --help)" << endl;
80  return 0;
81  }
82 
83  // read and show image
85  int r = BIAS::ImageIO::Load(*param.GetParamString("image"),image);
86  if ( r != 0 ) {
87  BIASERR("error loading image: "<<(*param.GetParamString("image")));
88  }
89 
91  target(image.GetWidth(), image.GetHeight(), image.GetChannelCount());
92  target.Clear(0);
93 
94  cout << "image width = " << image.GetWidth() << endl;
95  cout << "image height = " << image.GetHeight() << endl;
96 
97  // set the interpolation method
98  InterpolationMethod method =
99  (InterpolationMethod)(*(param.GetParamEnum("method")));
100 
101  // set the principal point of the cylinder camera
102  double hx = *(param.GetParamDouble("hx"));
103  if (hx > 0) cout << "Setting hx to " << hx << endl;
104  double hy = *(param.GetParamDouble("hy"));
105  if (hy > 0) cout << "Setting hy to " << hy << endl;
106 
107  // initialize time measurement
108  BIAS::TimeMeasure timer;
109 
110  // perform the mapping
111  CylinderMapping mapping;
112  if (hx > 0 && hy > 0) mapping.setPrincipalPoint(hx, hy);
113  mapping.setFocalLength(*param.GetParamDouble("focal"),
114  *param.GetParamDouble("focal"));
115 
116  timer.Start();
117  mapping.Map(image, target, method);
118  timer.Stop();
119  cout<<"Time consumed for mapping: "<<1e-3*timer.GetRealTime()<<" ms\n";
120 
121 /*
122  const int times = 100;
123  double timeSum = 0, timeSqSum = 0;
124  for (int t = 1; t <= times; t++) {
125  timer.Reset();
126  timer.Start();
127  smapping.Map(image, target, method);
128  timer.Stop();
129  const double time = 1e-3*timer.GetRealTime();
130  timeSum += time;
131  timeSqSum += (time*time);
132  cout<<"Time consumed for mapping: " << timeSum/(double)t << " +- "
133  << sqrt(timeSqSum/(double)t - (timeSum*timeSum)/(double)(t*t))
134  << " ms in " << t << "/" << times << " repetitions.\n";
135  }
136 */
137 
138  BIAS::ImageIO::Save("ExampleCylinderMapping.mip", target);
139  cout<<"Mapped image written to ExampleCylinderMapping.mip"<<endl;
140 }
double * GetParamDouble(const std::string &name) const
Definition: Param.cpp:665
InterpolationMethod
accuracy for resampling
void setFocalLength(const double fx, const double fy)
Set the focal length of the camera.
void DisableDestructorWarning()
Uses this just before end of your program to avoid error from destructor.
Definition: Param.hh:513
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:351
int * AddParamEnum(const std::string &name, const std::string &help, const std::vector< std::string > &enums, const int deflt=0, const std::vector< int > *IDs=NULL, const char cmdshort=0, const int Group=GRP_NOSHOW)
Definition: Param.cpp:468
int * GetParamEnum(const std::string &name) const
Definition: Param.cpp:712
unsigned int GetWidth() const
Definition: ImageBase.hh:312
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Definition: Param.cpp:1028
bool * GetParamBool(const std::string &name) const
Definition: Param.cpp:633
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
Definition: Param.cpp:176
void Clear(const StorageType value=0)
sets all pixels to zero/value
Definition: Image.hh:289
std::string * GetParamString(const std::string &name) const
Definition: Param.cpp:649
void setPrincipalPoint(const double px, const double py)
Set the principal point of the camera.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
unsigned int GetHeight() const
Definition: ImageBase.hh:319
int Map(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod=MapTrilinear, bool newSink=false, double SuperSampling=1.0)
backward mapping with various interpolations
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
double GetRealTime() const
return real time (=wall time clock) in usec JW For Win32: real-time is measured differently from user...
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
functions for spherical undistortion of given images, needs image dimensions, principal point and foc...
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
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111