X-Boost  2.3.8
IntegralImagePreprocessors.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  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _INTEGRAL_IMAGE_PREPROCS_H
22 #define _INTEGRAL_IMAGE_PREPROCS_H
23 
29 #include "IntegralImage.h"
30 
31 #include <string.h>
32 
37 public:
38 
41 
44 
46  typedef std::pair<DataType, ParamType> ReturnType;
47 
48 public:
49 
51 
52  IntegralImagePreprocessor(std::istream & in) {
53 
54  }
55 
57  void GetConf(char* strconf) const
58  {
59  if(strconf)
60  strconf[0] = 0;
61  }
62 
64  void Configure(char* strconf) const
65  {
66  // NOTHING
67  }
68 
69  void Configure(std::istream & in) {
70  // NOTHING
71  }
72 
74  unsigned int DataSize(unsigned int width, unsigned int height) const
75  {
76  return sizeof(uint32_t) * (width + 1) * (height + 1);
77  }
78 
80  void Serialize(unsigned char *buf, const IntegralImageData & src, int n) const
81  {
82  memcpy(buf, src.data, n);
83  }
84 
86  void DeSerialize(IntegralImageData & dst, const unsigned char *buf, int n) const
87  {
88  dst.data = new uint32_t[n/4];
89  memcpy(dst.data, buf, n);
90  }
91 
93  static void GetParam(IntegralImageParams & params, unsigned int width, unsigned int height)
94  {
95  params.stride = width+1;//width
96  params.width = width;
97  params.height = height;
98  }
99 
101  template<class T>
102  static bool Process(std::pair<IntegralImageData, IntegralImageParams> & out, const T *image, unsigned int width, unsigned int height, long stride)
103  {
104  IntegralImageHandle<uint32_t> integral_image;
105  integral_image.Build(image, width, height, stride, true); // NOTE: costruisco una EXTENDEND integral image, il punto (1,1) corrisponde al punto (0,0)
106 
107  out.first.data = integral_image.data;
108 
109  out.second.width = width; // pattern geometry (not integral_image)
110  out.second.height = height; // pattern geometry
111  out.second.stride = integral_image.width; // stride for integral image (uint32_t)
112  return true;
113  }
114 
116  static bool Process(std::pair<IntegralImageData, IntegralImageParams> & out, const IntegralImageHandle<uint32_t> & src)
117  {
118  out.first.data = src.data;
119 
120  out.second.width = src.width-1; // pattern geometry (not integral_image)
121  out.second.height = src.height-1; // pattern geometry
122  out.second.stride = src.width; // stride for integral image (uint32_t)
123  return true;
124  }
125 
126 };
127 
128 
129 #endif
T * data
Definition: IntegralImage.h:48
IntegralImageData DataType
Data provided by this Preprocessor.
Definition: IntegralImagePreprocessors.h:40
unsigned int DataSize(unsigned int width, unsigned int height) const
compute memory required to serialize/deserialize the preprocessed image
Definition: IntegralImagePreprocessors.h:74
Definition: IntegralImagePreprocessors.h:36
a descritor based on a integral image
void GetConf(char *strconf) const
return null string configuration
Definition: IntegralImagePreprocessors.h:57
static bool Process(std::pair< IntegralImageData, IntegralImageParams > &out, const IntegralImageHandle< uint32_t > &src)
the operator used to convert an integral image to the data
Definition: IntegralImagePreprocessors.h:116
static bool Process(std::pair< IntegralImageData, IntegralImageParams > &out, const T *image, unsigned int width, unsigned int height, long stride)
the operator used to convert an image to an integral image
Definition: IntegralImagePreprocessors.h:102
unsigned int width
probably an offset is better than stride
Definition: IntegralImageData.h:33
void DeSerialize(IntegralImageData &dst, const unsigned char *buf, int n) const
to store on disk or use with MPI
Definition: IntegralImagePreprocessors.h:86
unsigned int width
Definition: IntegralImage.h:50
void Configure(char *strconf) const
in haar preprocessor nothing to do
Definition: IntegralImagePreprocessors.h:64
static void GetParam(IntegralImageParams &params, unsigned int width, unsigned int height)
compute the params required to addess a image of width x height pixels
Definition: IntegralImagePreprocessors.h:93
il dato IntegralImage e' pressoche' equivalente a quello di RawData < uint32_t >
Definition: IntegralImageData.h:52
void Build(const _S *src, unsigned int width, unsigned int height, long stride, bool extend=false)
Build integral image from buffer.
Definition: IntegralImage.h:202
void Serialize(unsigned char *buf, const IntegralImageData &src, int n) const
to store on disk or use with MPI
Definition: IntegralImagePreprocessors.h:80
std::pair< DataType, ParamType > ReturnType
Data provided by this preprocessor.
Definition: IntegralImagePreprocessors.h:46
parameters required to access to integral image and to create features
Definition: IntegralImageData.h:31
IntegralImageParams ParamType
parameters used to store data and use with feature extractor
Definition: IntegralImagePreprocessors.h:43