Basic Image AlgorithmS Library 2.8.0

ExampleTransformToCartesian.cpp

00001 /* 
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005 Multimediale Systeme der Informationsverarbeitung
00006 Institut fuer Informatik
00007 Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 
00026 /**
00027    @example ExampleTransformToCartesian.cpp
00028    @relates ProjectionParametersPerspective
00029    @brief small example demonstrating the TransformToCartesian Function
00030    @ingroup g_examples
00031    @author ischiller 06/2010
00032 */
00033 
00034 #include <Geometry/Projection.hh>
00035 #include <Geometry/ProjectionParametersPerspective.hh>
00036 #include <Base/Image/Image.hh>
00037 #include <Base/Image/ImageIO.hh>
00038 #include <Utils/Param.hh>
00039 #include <Utils/IOUtils.hh>
00040 
00041 using namespace BIAS;
00042 using namespace std;
00043 
00044 
00045 int main(int argc, char *argv[])
00046 {
00047 
00048     Param params;
00049     string *proj = params.AddParamString("Projection","The projection to use, not mandatory","", 'p');
00050     string *image = params.AddParamString("Image","The float (depth) image to use, not mandatory","", 'i');
00051 
00052   if (!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
00053   { return 0; }
00054 
00055     Projection projection;
00056 
00057   int ret = 0;
00058 
00059   if(*proj!=""){
00060     ret = projection.XMLRead(*proj);
00061     cout<<"Loaded projection:"<<*proj<<endl;
00062    }
00063    if(string(*proj)=="" || ret < 0){
00064     ProjectionParametersPerspective ppp;
00065     ppp.SetSimplePerspective(40,176,144); //typical PMD camera
00066     ppp.SetFocalLengthAndAspect(250.0,1.0);
00067     ppp.ValidatePose();
00068     projection.AddAbsoluteCamera(&ppp);
00069     cout<<"Generated sample projection."<<endl;
00070    }
00071 
00072   Image<float> depthImg,cartDepthImg,polarDepthImg;
00073   if(*image !=""){
00074     ret = ImageIO::Load(*image,polarDepthImg );
00075     cout<<"Loaded image :"<<*image<<endl;
00076   }
00077   if(string(*image)=="" || ret < 0){
00078     depthImg.Init(176,144,1);
00079     depthImg.FillImageWithConstValue(2000.0);
00080     cout<<"Filled standard image with 5000mm.";
00081 
00082     if((dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))!= NULL){
00083         (dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
00084                 TransformCartesianToPolarCoordinates(depthImg, polarDepthImg);
00085     }
00086     cout<<" ..and transformed to polar."<<endl;
00087   }
00088 
00089   ImageIO::Save("polarInput.mip",polarDepthImg);
00090 
00091   if((dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))!= NULL){
00092     (dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
00093             TransformPolarToCartesianCoordinates(polarDepthImg, cartDepthImg);
00094      ImageIO::Save("cartesianOutput.mip",cartDepthImg);
00095     (dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
00096         TransformCartesianToPolarCoordinates(cartDepthImg,polarDepthImg);
00097      ImageIO::Save("polarOutput.mip",polarDepthImg);
00098 
00099     cout<<"Transformed Images."<<endl;
00100   }
00101   else {
00102     BIASERR("Not a perspective camera");
00103     return -1;
00104   }
00105 
00106   return 0;
00107 }
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends