Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleIplWrapOpenCV.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 ExampleIplWrapOpenCV.cpp
27  @relates WrapBias2Ipl
28  @brief howto use the wrapper to use a BIAS imaeg with OpenCV image algorithms
29  @ingroup g_examples
30  @author Woetzel
31 */
32 //#include <Base/Common/LeakChecking.h>
33 
34 #include <iostream>
35 #include <string>
36 
37 // BIAS
38 #include <Base/Image/Image.hh>
39 #include <Base/Image/ImageIO.hh>
40 #include <Base/Image/WrapBias2Ipl.hh>
41 
42 
43 #include <bias_config.h>
44 #ifndef BIAS_HAVE_OPENCV
45 # error You need to enable OPENCV to compile this file. Please reconfigure BIAS with USE_OPENCV
46 #endif
47 #include "cv.h"
48 //#include "highgui.h"
49 
50 using namespace std;
51 using namespace BIAS;
52 
53 int main( int argc, char** argv ){
54  bool darttest=false;
55  if (argc>=2) if (strcmp(argv[1],"-darttest")==0) {
56  darttest=true;
57  std::cout<<"started dart test: "<<argv[0]<<std::endl;
58  }
59 
60  // load a BIAS image to work with:
61  string filename( BIAS_TESTS_DATA "r4.jpg" );
62  if (!darttest && (argc>1)) filename=argv[1];
64  if (BIAS::ImageIO::Load(filename, img) !=0){
65  cout<<"error loading image "<<filename<<endl;
66  return -1;
67  };
68  cout<<"loaded image with dim: "<<img.GetWidth()<<"x"<<img.GetHeight()<<endl;
69 
70  // wrapper to use BIAS image in OpenCV:
71  WrapBias2Ipl wrap(&img);
72 
73  // work: draw something:
74  {
75  cvLine( wrap.p_imgIpl,
76  cvPoint(-20,0),
77  cvPoint(200,200),
78  cvScalar(255, 0, 0),
79  1, 8, 0 );
80  cvEllipse( wrap.p_imgIpl,
81  cvPoint(50,100),
82  cvSize(20,40),
83  20,
84  0, 270,
85  cvScalar(0,255,0) );
86 
87  string msg("Hello BIAS world! 1234567890");
88  int linetype=CV_AA; // antialiased
89  CvFont font1, font2, font3;
90  cvInitFont( &font1, CV_FONT_HERSHEY_SIMPLEX,
91  1.0, 1.0,
92  0, 1, linetype);
93  cvInitFont( &font2, CV_FONT_HERSHEY_PLAIN,
94  1.0, 1.0,
95  0, 1, 0);
96  cvInitFont( &font3,
97  CV_FONT_HERSHEY_COMPLEX, // font name
98  1.0, // hscale
99  1.0, // vscale
100  0, // shear
101  2, // thickness
102  linetype
103  );
104  cvPutText( wrap.p_imgIpl, msg.c_str(),
105  cvPoint(100,50), &font1, cvScalar(255,0,0) );
106  cvPutText( wrap.p_imgIpl, msg.c_str(),
107  cvPoint(100,100), &font2, cvScalar(0,255,0) );
108  cvPutText( wrap.p_imgIpl, msg.c_str(),
109  cvPoint(100,150), &font3, cvScalar(0,0,255) );
110  }
111 
112  // display using CV routines
113  // color channel order may be wrong! (use fixed highgui)
114  // avoid gui display on darttest because it doesn't work on Linux without login.
115  if (!darttest) wrap.Display(true, 2000);
116 
117  // output to disk:
118  //cvSaveImage("out_wrapIPL.jpg", wrap.p_imgIpl);
119  BIAS::ImageIO::Save("out_ExampleIplWrapOpenCV.jpg", *wrap.p_imgBias, BIAS::ImageIO::FF_jpg);
120 
121  return 0;
122 }
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
wrapper around a BIAS image to be used as an OpenCv IPlimage with shared data area.
Definition: WrapBias2Ipl.hh:26