Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biastofdepthundist.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 #include <Geometry/ProjectionParametersPerspectiveDepth.hh>
26 #include <Utils/Param.hh>
27 #include <Utils/IOUtils.hh>
28 #include <Base/Common/FileHandling.hh>
29 
30 using namespace std;
31 using namespace BIAS;
32 
33 /**
34  @file
35  @ingroup g_tools
36  @brief Undistorts the depth map in the sense of ToF-camera depth distortion,
37  without touching the lens distortion, see biastofdepthundist.cpp.
38  Expects parameters in the header and is adding fitting params to output image's header.
39  @author bartzcak
40  */
41 int
42 main(int argc, char* argv[])
43 {
44 
45  Param params(true);
46  string* inputCameraName = params.AddParamString("inputCam",
47  "input camera/image with params in the header", "", 'i');
48 
49  string* inputCameraNameList = params.AddParamString("inputCamList",
50  "input cameras/images with params in the header", "", 'l');
51 
52  if (!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
53  {
54  return -1;
55  }
56 
57  Camera<float> inputCamera;
58  Projection proj;
59 
60  if (!((*inputCameraName).compare("") == 0))
61  {
62  if (!IOUtils::LoadCamera(inputCameraName, inputCamera, proj))
63  {
64  return -1;
65  }
67  if (!IOUtils::CheckType<ProjectionParametersPerspectiveDepth,
69  {
70  BIASERR("expected parameters of type ProjectionParametersPerspectiveDepth!");
71  return -1;
72  }
73 
74  if (!pppd->HasDepthDistortion())
75  {
76  cout << "nothing to un-distort!\n";
77  return 0;
78  }
79 
80  if (pppd->UnDistortDepthMapIP(inputCamera) != 0)
81  {
82  BIASERR("something went wrong!");
83  return -1;
84  }
85 
87 
88  string outputCameraName;
89  outputCameraName = FileHandling::Basename(*inputCameraName);
90  if (!IOUtils::SaveCamera("dud-" + outputCameraName + ".mip", inputCamera,
91  Projection(*pppd)))
92  {
93  return -1;
94  }
95  }
96 
97  vector<string> imageList;
98  if (!((*inputCameraNameList).compare("") == 0))
99  {
100  if (Param::ParseListFile(*inputCameraNameList, imageList) != 0)
101  {
102  BIASERR("error parsing "<< (*inputCameraNameList) << endl);
103  return -1;
104  }
105  else
106  {
107  cout << "loaded " << (*inputCameraNameList) << endl;
108 
109  for (unsigned int i = 0; i < imageList.size(); i++)
110  {
111  string inputCameraName = imageList[i];
112  if (!IOUtils::LoadCamera(inputCameraName, inputCamera, proj))
113  {
114  return -1;
115  }
117  if (!IOUtils::CheckType<ProjectionParametersPerspectiveDepth,
119  {
120  BIASERR("expected parameters of type ProjectionParametersPerspectiveDepth!");
121  return -1;
122  }
123 
124  if (!pppd->HasDepthDistortion())
125  {
126  cout << "nothing to un-distort!\n";
127  return 0;
128  }
129 
130  if (pppd->UnDistortDepthMapIP(inputCamera) != 0)
131  {
132  BIASERR("something went wrong!");
133  return -1;
134  }
135 
136  pppd->SetDepthDistortionToZero();
137 
138  string outputCameraName;
139  outputCameraName = FileHandling::Basename(inputCameraName);
140  if (!IOUtils::SaveCamera("dud-" + outputCameraName + ".mip",
141  inputCamera, Projection(*pppd)))
142  {
143  return -1;
144  } else {
145  cout << "written: dud_" << outputCameraName << endl;
146  }
147  }
148  }
149  }
150 
151  return 0;
152 }
153 
additional depth calibration parameters for a perspective depth camera to be used for ToF-(PMD) camer...
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
This class Param provides generic support for parameters.
Definition: Param.hh:231
int UnDistortDepthMapIP(BIAS::Image< float > &depthMap, bool bIsInCartesianCoords=false)
Undistorts the passed depth map in place.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
bool HasDepthDistortion() const
checks whether depth distortion is present
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