Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleMetaData.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  @example ExampleMetaData.cpp
27  @relates Image, MetaData
28  @brief Example for Image/Camera Meta Data usage
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 // must be first:
34 //#include <Base/Common/LeakChecking.h>
35 
36 #include <Base/Image/Image.hh>
37 #include <Base/Image/ImageIO.hh>
38 
39 #include <sstream>
40 
41 // usually this comes from Base/Geometry/HomgPoint2D.hh
42 #define HOMGPOINT2D_TYPE double
43 
44 using namespace BIAS;
45 using namespace std;
46 
47 int main()
48 {
49  Image<unsigned char> im(256, 256, 1), im2, im3;
50  MetaData *md=NULL;
51  // point and point2 should be a HomgPoint2D,
52  // they are not of type HomgPoint2D because no cross dependencies
53  // between Base/Image and Base/Geometry are desired
54  double point[]={2.0, 3.0, 1.0}, point2[3]={0.0, 0.0, 0.0};
55  ostringstream ascii;
56  string filename="metadata";
57  string mipfilename=filename+".mip";
58  string pgmfilename=filename+".pgm";
59  string tag;
60  AppData appdata;
61 
62  md=im.GetMetaData();
63  BIASASSERT(md!=NULL);
64  md->Add(AppData::MD_HomgPoint2D, sizeof(HOMGPOINT2D_TYPE)*3,
65  (char *)point);
66  md->Add(AppData::MD_HomgPoint2D, sizeof(HOMGPOINT2D_TYPE)*3,
67  (char *)point);
68 
69  ascii <<" [ "<<point[0]<<" "<<point[1]<<" "<<point[2]<<" ]";
70  md->Add("#[HomgPoint2D]", ascii.str());
71  md->Add("#[HomgPoint2D]", ascii.str());
72 
73 
74  //if (ImageIO::Save(filename, im)!=0){
75  if (ImageIO::Save(filename, im)!=0){
76  BIASERR("error writing image "<<filename);
77  }
78  if (ImageIO::Save(filename, im, ImageIO::FF_pgm)!=0){
79  BIASERR("error exporting image "<<filename);
80  }
81 
82  //if (ImageIO::Load(mipfilename, im2)!=0){
83  if (ImageIO::Load(mipfilename, im2)!=0){
84  BIASERR("error reading image "<<filename<<".mip");
85  }
86  md=im2.GetMetaData();
87  BIASASSERT(md!=NULL);
88  cerr << "found "<<md->size()<<" metadatas in "<<mipfilename<<endl;
89  md->Dump();
90 
91 
92  if (md->Find(AppData::MD_HomgPoint2D, appdata)!=-1){
93  point2[0]=((HOMGPOINT2D_TYPE *)appdata.data)[0];
94  point2[1]=((HOMGPOINT2D_TYPE *)appdata.data)[1];
95  point2[2]=((HOMGPOINT2D_TYPE *)appdata.data)[2];
96  cout << " found MD_HomgPoint2D in "<<filename<<".mip : [ "
97  <<point2[0]<<" "<<point2[1]<<" "<<point2[2]<<" ]"<<endl;
98  } else {
99  BIASERR("MD_HomgPoint2D not found in "<<filename<<".mip");
100  }
101 
102  if (ImageIO::ImportImage(pgmfilename, im3)!=0){
103  BIASERR("error importing image "<<filename);
104  }
105 
106  md=im3.GetMetaData();
107  BIASASSERT(md!=NULL);
108  cerr << "found "<<md->size()<<" metadatas in "<<pgmfilename<<endl;
109  md->Dump();
110 
111  if (md->Find("#[HomgPoint2D]", appdata)!=-1){
112  cout << " found ascii in "<<filename<<".pgm : "
113  <<appdata.stag<<appdata.sdata<<endl;
114  } else {
115  BIASERR("#[HomgPoint2D] not found in "<<filename<<".pgm");
116  }
117 
118  return 0;
119 }
std::string stag
the tag as given in ascii meta data
Definition: MetaData.hh:100
static int ImportImage(const std::string &filename, ImageBase &result)
Try to load/import an image from a file using external libs.
Definition: ImageIO.cpp:378
MetaData * GetMetaData()
Definition: ImageBase.hh:456
void Add(enum AppData::TAppData ID, unsigned int length, char *data)
Add a new binary meta datum.
Definition: MetaData.cpp:317
std::string sdata
the data as given in ascii meta data
Definition: MetaData.hh:102
char * data
pointer to block of data
Definition: MetaData.hh:98
int Find(const enum AppData::TAppData tag, AppData &data) const
searches for tag in binary coded AppDatas.
Definition: MetaData.cpp:363
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
this class collects all additional data chunks of type AppData to be written into/read from an image ...
Definition: MetaData.hh:121
void Dump(std::ostream &os=std::cout)
dumps this to cout, unfinished piece of code
Definition: MetaData.cpp:460
this is a chunk of metadata, also see MetaData
Definition: MetaData.hh:49