Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleIplImageDraw.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 ExampleIplImageDraw.cpp
27  @relates ImageDraw
28  @brief OpenCV/IPL image draw
29  @ingroup g_examples
30  @author Woetzel
31 */
32 
33 #include <iostream>
34 #include <string>
35 
36 // BIAS
37 #include <Base/Image/Image.hh>
38 #include <Base/Image/ImageIO.hh>
39 #include <Base/ImageUtils/ImageDraw.hh>
40 #include <Base/Image/ColourRGB.hh>
41 
42 
43 using namespace std;
44 using namespace BIAS;
45 
46 
47 int main( int argc, char** argv ){
48  int result=0;
49  bool darttest=false;
50  if (argc>=2) if (strcmp(argv[1],"-darttest")==0) {
51  darttest=true;
52  std::cout<<"started dart test: "<<argv[0]<<std::endl;
53  }
54  //
55  // load a BIAS image to work with:
56  //
57  string filename( BIAS_TESTS_DATA "r4.jpg" );
58  if (!darttest && (argc>1)) filename=argv[1];
60  if (BIAS::ImageIO::Load(filename, img) !=0){
61  cout<<"error loading image "<<filename<<endl;
62  return -1;
63  };
64  cout<<"loaded image "<<filename<<" with dim: "<<img.GetWidth()<<"x"<<img.GetHeight()<<endl;
65 
66  //
67  // OK, work:
68  //
69  {
70  ImageDraw<unsigned char>::Circle(img, 100,100, 90 );
71  ImageDraw<unsigned char>::Circle(img, 100,150, 40,COLOR_RED,
72  5, CV_AA, 0 );
73  ImageDraw<unsigned char>::Line(img, 10,10, 100,100,
74  ColourRGB<unsigned char>(42,12,255),
75  25, // thickness
76  CV_AA
77  );
78 
80  ,200,300 // center
81  ,150, 50 // axes
82  ,45 // orientation
83  ,0, 270 // paint angle from..to
84  ,COLOR_WHITE
85  ,20
86  );
87 
89  100,100,
90  150,200,
91  COLOR_BLACK,
92  8
93  );
94 
95 
96 
97  ImageDraw<unsigned char>::Text(img, "Hello BIAS!!", 10,50 );
98  ImageDraw<unsigned char>::Text(img, "ExampleIplImageDraw.cpp RED", 10, 100, COLOR_RED );
99  ImageDraw<unsigned char>::Text(img, "ExampleIplImageDraw.cpp GREEN",10, 150, COLOR_GREEN );
100  ImageDraw<unsigned char>::Text(img, "ExampleIplImageDraw.cpp BLUE", 10, 200, COLOR_BLUE );
101  ImageDraw<unsigned char>::Text(img, "Renault 4TL rocks ;-)", 10, 250, COLOR_BLUE,
102  CV_FONT_HERSHEY_SIMPLEX, 1.5, 1.5, 0, 2, CV_AA);
103  ImageDraw<unsigned char>::Text(img, argv[0] , 0, 300, COLOR_WHITE,
104  CV_FONT_HERSHEY_PLAIN, 0.8, 1.2, 0, 1, CV_AA);
105  }
106 
107  //
108  // output result:
109  //
110  string outFn("out_ExampleIplImageDraw.jpg");
111  result=BIAS::ImageIO::Save(outFn, img, BIAS::ImageIO::FF_jpg);
112  //string outFn("out_ExampleIplImageDraw.png");
113  //result=BIAS::ImageIO::Save(outFn, img, BIAS::ImageIO::FF_png);
114  if (result==0) cout<<"wrote "<<outFn<<endl;
115 
116 
117  // ---- Example for Dart attachment adta submission (Jan Woetzel) ----
118  //
119  // attach Dart client xml data for submission to dart server (JW):
120  // jpeg is much smaller.
121  cout<<endl
122  //<<"<DartMeasurementFile name=\"outputImage1\" type=\"image/png\">"<<outFn<<"</DartMeasurementFile>"
123  <<"<DartMeasurementFile name=\"outputImage1\" type=\"image/jpeg\">"<<outFn<<"</DartMeasurementFile>"
124  <<endl;
125 
126  return result;
127 }
128 
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetHeight() const
Definition: ImageBase.hh:319
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
drawing simple entities into the image like rectangles or lines As all functions are static they have...
Definition: ImageDraw.hh:72