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

example for usage of PMD (ToF)-ImgeIO

, PMDImageIO

Author
MIP
/*
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 ExamplePMDImageIO.cpp
@relates PMDImageProc, PMDImageIO
@brief example for usage of PMD (ToF)-ImgeIO
@ingroup g_examples
@author MIP
*/
#include <iostream>
#include <Base/Image/ImageBase.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
#include <Image/PMDImageProc.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[]) {
Image<float> dim, dim2, mcim, mcim2;
string PMDName = "img.tif";
string PMDNameXML = "";
PMDImageMetaData meta, meta2, metad, metad2, metadum;
cout<<"ExamplePMDImageIO:"<<endl;
if (argc>1) {
if (strstr(argv[1],".xml")!=NULL) {
PMDNameXML = argv[1];
} else if (strstr(argv[1],".tif")!=NULL) {
PMDName = argv[1];
} else if (strstr(argv[1],".bmp")!=NULL) {
PMDImageIO::LoadFromTXT(48, 64, argv[2], argv[3], argv[4],
im, dim, mcim, metad);
if (argc<=1 || ImageIO::Load(argv[1], im)!=0){
cerr << argv[1] << " <image>\n";
im.Init(640, 480, 3);
} else {
cout << "Read 2D-image:" << argv[1] << endl;
}
meta.width = im.GetWidth();
meta.height = im.GetHeight();
meta.channels = 1;
meta.PrincipalX = (double)im.GetWidth()/2.0;
meta.PrincipalY = (double)im.GetHeight()/2.0;
meta.FocallengthX = metad.FocallengthX*((double)im.GetWidth()/(double)dim.GetWidth());
meta.AspectRatio = 1;
meta.UndistCoeff[0] = 0;
meta.UndistCoeff[1] = 0;
meta.UndistCoeff[2] = 0;
meta.UndistCoeff[3] = 0;
meta.CameraCenter[0] = 0;
meta.CameraCenter[1] = 0;
meta.CameraCenter[2] = 0;
meta.CameraRotation[0] = 0;
meta.CameraRotation[1] = 0;
meta.CameraRotation[2] = 0;
metadum = metad;
meta, metadum);
PMDImageIO::Save("img.tif", im, dim, mcim, meta, metad);
cout << "Wrote img.tif" << endl;
cout << "Metadata set: " << endl
<< meta.PrincipalX << " " << meta.PrincipalY << " "
<< meta.FocallengthX << " " << meta.AspectRatio << " " ;
} else {
if (argc<=1 || ImageIO::Load(argv[1], im)!=0){
cerr << argv[1] << " <image>\n";
im.Init(640, 480, 3);
} else {
cout << "Read 2D-image:" << argv[1] << endl;
}
if (argc<=2 || ImageIO::Load(argv[2], dim)!=0){
cerr << argv[2] << " <image>\n";
} else {
cout << "Read depth-image:" << argv[2] << endl;
}
if (argc<=3 || ImageIO::Load(argv[3], mcim)!=0){
cerr << argv[3] << " <image>\n";
} else {
cout << "Read modulation-coefficients-image:" << argv[3] << endl;
}
meta.PrincipalX = 100;
meta.PrincipalY = 200;
meta.FocallengthX = 300;
meta.AspectRatio = 1;
meta.UndistCoeff[0] = 1;
meta.UndistCoeff[1] = 1.3;
meta.UndistCoeff[2] = 1.6;
meta.UndistCoeff[3] = 1.9;
metad.PrincipalX = 1100;
metad.PrincipalY = 1200;
metad.FocallengthX = 1300;
metad.AspectRatio = 1.8;
metad.UndistCoeff[0] = 1.8;
metad.UndistCoeff[1] = 1.34;
metad.UndistCoeff[2] = 1.64;
metad.UndistCoeff[3] = 1.94;
PMDImageIO::Save("img.tif", im, dim, mcim, meta, metad);
cout << "Wrote img.tif" << endl;
cout << "Metadata set: " << endl
<< meta.PrincipalX << " " << meta.PrincipalY << " "
<< meta.FocallengthX << " " << meta.AspectRatio << " " ;
for (int i=0; i<4; i++) {
cout << meta.UndistCoeff[i] << " " ;
}
cout << endl;
}
}
if (PMDNameXML!="") {
#ifdef BIAS_HAVE_XML2
PMDImageIO::Load(PMDNameXML, im2, dim2, mcim2, meta2, metad2);
PMDImageIO::Save(PMDName, im2, dim2, mcim2, meta2, metad2);
#else
BIASERR("USE_XML2 switched off, cannot parse xml-file!");
BIASABORT;
#endif
} else {
PMDImageIO::Load(PMDName, im2, dim2, mcim2, meta2, metad2);
}
cout << "Read " << PMDNameXML << " or " << PMDName << endl;
cout << "Metadata read: " << endl
<< meta2.PrincipalX << " " << meta2.PrincipalY << " "
<< meta2.FocallengthX << " " << meta2.AspectRatio << " "
<< meta2.width << " " << meta2.height << " "
<< meta2.channels << " ";
cout << "|";
for (int i=0; i<4; i++) {
cout << meta2.UndistCoeff[i] << " " ;
}
cout << "|";
for (int i=0; i<3; i++) {
cout << meta2.CameraCenter[i] << " ";
}
cout << "|";
for (int i=0; i<3; i++) {
cout << meta2.CameraRotation[i] << " ";
}
cout << endl << "Metadata depth read: " << endl
<< metad2.PrincipalX << " " << metad2.PrincipalY << " "
<< metad2.FocallengthX << " " << metad2.AspectRatio << " "
<< metad2.width << " " << metad2.height << " "
<< metad2.channels ;
cout << "|";
for (int i=0; i<4; i++) {
cout << metad2.UndistCoeff[i] << " " ;
}
cout << "|";
for (int i=0; i<3; i++) {
cout << metad2.CameraCenter[i] << " ";
}
cout << "|";
for (int i=0; i<3; i++) {
cout << metad2.CameraRotation[i] << " ";
}
cout << endl;
if (!im2.IsEmpty())
ImageIO::Save("img.pgm", im2);
if (!dim2.IsEmpty())
ImageIO::Save("imgdepth.mip", dim2);
if (!mcim2.IsEmpty())
ImageIO::Save("imgModCoeff.mip", mcim2);
}