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

shows usage of the changed UndistortionMapping class

Author
bangerer (updated version)
Date
09/2009
/*
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 ExampleUndistort.cpp
* @relates UndistortionMapping
* @brief shows usage of the changed UndistortionMapping class
* @author bangerer (updated version)
* @date 09/2009
*/
#include <bias_config.h>
#ifndef BIAS_HAVE_XML2
# error You need XML2 to compile this code. Please enable USE_XML2 and recompile BIAS.
#endif // BIAS_HAVE_XML2
#include <Image/ProjectionMapping.hh>
#include <Geometry/Projection.hh>
#include <Geometry/ProjectionParametersPerspective.hh>
#include <Geometry/ProjectionParametersSpherical.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <iostream>
using namespace BIAS;
using namespace std;
int main(int argc, char** argv )
{
if (argc<3 ) {
cout <<"Usage: ExampleUndistort <image> <projection.xml>"<<endl;
exit(1);
}
// read projection from file
string camfile = argv[2];
int ret = proj.XMLRead(camfile);
if(ret < 0){
BIASERR("Error reading Projection:"<<camfile);
return -1;
}
else cout<<"Read source projection:"<<camfile<<endl;
//decide if image is perspective or spherical
ppp = dynamic_cast<ProjectionParametersPerspective *>(proj.GetParameters());
if(ppp ==NULL){
BIASERR("Example only implemented for perspective cameras.");
return -1;
}
BIAS::Projection projSink(proj);
dynamic_cast<ProjectionParametersPerspective *>(projSink.GetParameters())->
SetUndistortion(0.0,0.0,0.0,0.0);
pm.SetSourceCam(proj);
pm.SetSinkCam(projSink);
// load source image
if (ImageIO::Load(argv[1], src)!=0){
BIASERR("error loading image "<<argv[1]);
return -1;
}
cout<<"Converting to RGB:"<<endl;
}
else{
cout<<"Colormodel is RGB:"<<endl;
}
dst.Init(src.GetWidth(),src.GetHeight(),src.GetChannelCount());
//you can either use lookuptable
//pm.PrepareLookupTableMapping(src,dst,MapTrilinear);
//pm.MapWithLookupTable(src,dst,MapTrilinear);
//or map without lookuptable
pm.Map(src,dst,MapTrilinear);
disp.Init(src.GetWidth(),src.GetHeight(),3);
pm.GetDisplacementMap(disp,src);
ImageIO::Save("UndistortedImage.mip", dst);
ImageIO::Save("DisplacementImage.mip", disp);
cout << " created: "<<"UndistortedImage.mip"<<endl;
cout << " created: "<<"DisplacementImage.mip"<<endl;
return 0;
}