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

Example for Image/Camera Meta Data usage

, MetaData

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 ExampleMetaData.cpp
@relates Image, MetaData
@brief Example for Image/Camera Meta Data usage
@ingroup g_examples
@author MIP
*/
// must be first:
//#include <Base/Common/LeakChecking.h>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <sstream>
// usually this comes from Base/Geometry/HomgPoint2D.hh
#define HOMGPOINT2D_TYPE double
using namespace BIAS;
using namespace std;
int main()
{
Image<unsigned char> im(256, 256, 1), im2, im3;
MetaData *md=NULL;
// point and point2 should be a HomgPoint2D,
// they are not of type HomgPoint2D because no cross dependencies
// between Base/Image and Base/Geometry are desired
double point[]={2.0, 3.0, 1.0}, point2[3]={0.0, 0.0, 0.0};
ostringstream ascii;
string filename="metadata";
string mipfilename=filename+".mip";
string pgmfilename=filename+".pgm";
string tag;
AppData appdata;
md=im.GetMetaData();
BIASASSERT(md!=NULL);
md->Add(AppData::MD_HomgPoint2D, sizeof(HOMGPOINT2D_TYPE)*3,
(char *)point);
md->Add(AppData::MD_HomgPoint2D, sizeof(HOMGPOINT2D_TYPE)*3,
(char *)point);
ascii <<" [ "<<point[0]<<" "<<point[1]<<" "<<point[2]<<" ]";
md->Add("#[HomgPoint2D]", ascii.str());
md->Add("#[HomgPoint2D]", ascii.str());
//if (ImageIO::Save(filename, im)!=0){
if (ImageIO::Save(filename, im)!=0){
BIASERR("error writing image "<<filename);
}
if (ImageIO::Save(filename, im, ImageIO::FF_pgm)!=0){
BIASERR("error exporting image "<<filename);
}
//if (ImageIO::Load(mipfilename, im2)!=0){
if (ImageIO::Load(mipfilename, im2)!=0){
BIASERR("error reading image "<<filename<<".mip");
}
md=im2.GetMetaData();
BIASASSERT(md!=NULL);
cerr << "found "<<md->size()<<" metadatas in "<<mipfilename<<endl;
md->Dump();
if (md->Find(AppData::MD_HomgPoint2D, appdata)!=-1){
point2[0]=((HOMGPOINT2D_TYPE *)appdata.data)[0];
point2[1]=((HOMGPOINT2D_TYPE *)appdata.data)[1];
point2[2]=((HOMGPOINT2D_TYPE *)appdata.data)[2];
cout << " found MD_HomgPoint2D in "<<filename<<".mip : [ "
<<point2[0]<<" "<<point2[1]<<" "<<point2[2]<<" ]"<<endl;
} else {
BIASERR("MD_HomgPoint2D not found in "<<filename<<".mip");
}
if (ImageIO::ImportImage(pgmfilename, im3)!=0){
BIASERR("error importing image "<<filename);
}
md=im3.GetMetaData();
BIASASSERT(md!=NULL);
cerr << "found "<<md->size()<<" metadatas in "<<pgmfilename<<endl;
md->Dump();
if (md->Find("#[HomgPoint2D]", appdata)!=-1){
cout << " found ascii in "<<filename<<".pgm : "
<<appdata.stag<<appdata.sdata<<endl;
} else {
BIASERR("#[HomgPoint2D] not found in "<<filename<<".pgm");
}
return 0;
}