Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleTransformToCartesian.cpp

small example demonstrating the TransformToCartesian Function

Author
ischiller 06/2010
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleTransformToCartesian.cpp
@relates ProjectionParametersPerspective
@brief small example demonstrating the TransformToCartesian Function
@ingroup g_examples
@author ischiller 06/2010
*/
#include <Geometry/Projection.hh>
#include <Geometry/ProjectionParametersPerspective.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Utils/Param.hh>
#include <Utils/IOUtils.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
Param params;
string *proj = params.AddParamString("Projection","The projection to use, not mandatory","", 'p');
string *image = params.AddParamString("Image","The float (depth) image to use, not mandatory","", 'i');
if (!IOUtils::ParseCommandLineEvalHelp(params, argc, argv))
{ return 0; }
Projection projection;
int ret = 0;
if(*proj!=""){
ret = projection.XMLRead(*proj);
cout<<"Loaded projection:"<<*proj<<endl;
}
if(string(*proj)=="" || ret < 0){
ppp.SetSimplePerspective(40,176,144); //typical PMD camera
ppp.SetFocalLengthAndAspect(250.0,1.0);
ppp.ValidatePose();
projection.AddAbsoluteCamera(&ppp);
cout<<"Generated sample projection."<<endl;
}
Image<float> depthImg,cartDepthImg,polarDepthImg;
if(*image !=""){
ret = ImageIO::Load(*image,polarDepthImg );
cout<<"Loaded image :"<<*image<<endl;
}
if(string(*image)=="" || ret < 0){
depthImg.Init(176,144,1);
depthImg.FillImageWithConstValue(2000.0);
cout<<"Filled standard image with 5000mm.";
if((dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))!= NULL){
(dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
TransformCartesianToPolarCoordinates(depthImg, polarDepthImg);
}
cout<<" ..and transformed to polar."<<endl;
}
ImageIO::Save("polarInput.mip",polarDepthImg);
if((dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))!= NULL){
(dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
TransformPolarToCartesianCoordinates(polarDepthImg, cartDepthImg);
ImageIO::Save("cartesianOutput.mip",cartDepthImg);
(dynamic_cast<ProjectionParametersPerspective*>(projection.GetParameters()))->
TransformCartesianToPolarCoordinates(cartDepthImg,polarDepthImg);
ImageIO::Save("polarOutput.mip",polarDepthImg);
cout<<"Transformed Images."<<endl;
}
else {
BIASERR("Not a perspective camera");
return -1;
}
return 0;
}