X-Boost  2.3.8
ImageClassifierWrapper.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  * Copyright (c) 2013-2014 Luca Castangia <l.caio@ce.unipr.it>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef _IMAGE_CLASSIFIER_WRAPPER_H
23 #define _IMAGE_CLASSIFIER_WRAPPER_H
24 
25 #include "Types.h"
26 #include "ImageClassifier.h"
27 
28 // #include "IO/pnmio.h"
29 
33 template<class _Instance, class _Preprocessor>
35 class ImageClassifierWrapper: public ImageClassifier, public _Preprocessor, public _Instance {
37  typename _Preprocessor::ReturnType m_clsf_data;
38 public:
39 
41  ImageClassifierWrapper(std::istream & in) : ImageClassifier(in), _Preprocessor(in), _Instance(in) { m_clsf_data.first.data=NULL; }
42 
43  virtual ~ImageClassifierWrapper() { Release(); }
44 
45 
46  static std::string signature() {
47  return _Instance::signature();
48  }
49 
50 
51  std::string getSignature() const {
52  return _Instance::signature();
53  }
54 
56  virtual void setImage(const unsigned char *ptr, long stride, unsigned int width, unsigned int height) {
57  // initialize m_clsf_data
58  _Preprocessor::Process(m_clsf_data, ptr, width, height, stride);
59  }
60 
62  virtual void Release() {
63  m_clsf_data.first.release();
64  }
65 
67  virtual float operator() (int x0, int y0) const {
68  return _Instance::operator()(getData1(m_clsf_data.first,m_clsf_data.second,x0,y0),getData2(m_clsf_data.first,m_clsf_data.second));
69  }
70 
72  virtual void Process (double *out, int x0, int y0, int n, int step) const {
73  for(int i=0; i<n; i+=step)
74  *out++=_Instance::operator()(getData1(m_clsf_data.first,m_clsf_data.second,x0+i,y0),getData2(m_clsf_data.first,m_clsf_data.second));
75  }
76 
77 };
78 
79 #endif
ImageClassifierWrapper(std::istream &in)
[imageclassifier w,h] [preprocessor if any] [classifier data]
Definition: ImageClassifierWrapper.h:41
Types involved in boosting.
"Binary" Classifier, virtual class
Definition: ImageClassifier.h:37
virtual void Release()
release m_clsf_data
Definition: ImageClassifierWrapper.h:62
virtual float operator()(int x0, int y0) const
process single point of m_clsf_data
Definition: ImageClassifierWrapper.h:67
std::string getSignature() const
return the classifier signature
Definition: ImageClassifierWrapper.h:51
virtual void Process(double *out, int x0, int y0, int n, int step) const
process a row of m_clsf_data, with a fixed step
Definition: ImageClassifierWrapper.h:72
bridge for ImageClassifier
Definition: ImageClassifierWrapper.h:35
virtual classes to work on classifier. ImageClassifier is the simplest one, computing the response im...
virtual void setImage(const unsigned char *ptr, long stride, unsigned int width, unsigned int height)
initialize m_clsf_data
Definition: ImageClassifierWrapper.h:56