X-Boost  2.3.8
ObjectDetectorWrapper.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 _OBJECT_CLASSIFIER_WRAPPER_H
23 #define _OBJECT_CLASSIFIER_WRAPPER_H
24 
25 
28 #include "Traits/IntegralChannelFeature.h"
29 #include "Traits/HaarFeature.h"
30 
31 #include "Types.h"
32 #include "Utility/timer.h"
33 
34 //NMS
36 
37 #include "detail/IntegralChannelImage.h"
38 #include "detail/IntegralImage.h"
39 
40 
41 #include "ObjectDetector.h"
42 
43 
47 template<class _Instance, class _Preprocessor>
51 private:
54 
55 public:
56 
57  ObjectDetectorWrapper() : pHelper(0) { }
58 
59  ObjectDetectorWrapper(const char *filename) : pHelper(0)
60  {
62  addClassifier(filename, dummy);
63  }
64  virtual ~ObjectDetectorWrapper() {
65  delete pHelper;
66  }
67 
68  virtual int addClassifier(const char* pth_cls, const ObjectDetectorParams & params) {
69  std::ifstream fin(pth_cls);
70 
71  if(fin)
72  {
73  template_geometry geom;
74 
75  std::string code;
76 
77  fin >> code;
78  if (code != _Instance::signature())
79  {
80  std::cerr << "error in loading " << pth_cls << ": incompatible classifier" << std::endl;
81  return -1;
82  }
83 
84 
85  fin >> geom.width;
86  fin >> geom.height;
87 
88  if(pHelper == 0)
89  {
91  }
92  else
93  {
94  char pconf[16];
95  char conf[16];
96  pHelper->GetConf(pconf); // save Conf
97  // load new conf
98  pHelper->Configure(fin);
99  //
100  pHelper->GetConf(conf); // get new Conf
101 
102  if(strcmp(pconf,conf)!=0)
103  {
104  pHelper->Configure(pconf); // restore previous conf
105  std::cerr << "error in loading " << pth_cls << ": incompatible preprocessor" << std::endl;
106  return -1;
107  }
108  }
109 
110  // load classifier:
111  _Instance ogg(fin);
112  pHelper->m_classifs.push_back(ogg);
113  pHelper->m_clsparams.push_back(params);
114  pHelper->m_clsparams.back().sz = geom; // set the geometry
115 
116  return pHelper->m_clsparams.size() - 1;
117  }
118  else {
119  std::cerr << "error open "<<pth_cls<<std::endl;
120  return -1;
121  }
122  }
123 
124 
125  static std::string signature() {
126  return _Instance::signature();
127  }
128 
130  std::string getSignature() const {
131  return _Instance::signature();
132  }
133 
134  void setParams(const ObjectDetectorGlobalParams & params) {
135  pHelper->setParams(params);
136  }
137  const ObjectDetectorGlobalParams & getParams() const {
138  return pHelper->getParams();
139  }
140 
142  void setClassifierParams(int index, const ObjectDetectorParams & params) {
143  pHelper->setClassifierParams(index, params);
144  }
147  return pHelper->getClassifierParams(index);
148  }
149 
150 
151  virtual void Detect(std::vector<Candidate>& out, const ImageHandle & src) {
152  pHelper->detect(out, src);
153  }
154 };
155 
156 #endif
const ObjectDetectorParams & getClassifierParams(int index)
get per-classifier params
Definition: ObjectDetectorWrapper.h:146
Types involved in boosting.
virtual int addClassifier(const char *pth_cls, const ObjectDetectorParams &params)
Definition: ObjectDetectorWrapper.h:68
Definition: Image.h:35
Implement a local maxima search algorithm.
std::string getSignature() const
virtual
Definition: ObjectDetectorWrapper.h:130
Over-Classifier params.
Definition: ObjectDetector.h:68
Cross Platform High Performance timer.
image/size TODO namespace
Definition: Types.h:39
void setParams(const ObjectDetectorGlobalParams &params)
Set the Global Params.
Definition: ObjectDetectorWrapper.h:134
method to convert an image sample in integral image preprocessors
void setClassifierParams(int index, const ObjectDetectorParams &params)
set per-classifier params
Definition: ObjectDetectorWrapper.h:142
virtual classes to work on classifier. ObjectDetector exploits all the performance of classifier...
Definition: ObjectDetector.h:42
method to convert an image sample in integral Channels Image
Definition: ObjectDetectorWrapper.h:50
Definition: ObjectDetector.h:82
virtual void Detect(std::vector< Candidate > &out, const ImageHandle &src)
detect object
Definition: ObjectDetectorWrapper.h:151