Point Cloud Library (PCL)  1.14.0-dev
hog.h
1 /*
2  * Software License Agreement (Simplified BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2013-, Open Perception, Inc.
6  * Copyright (c) 2012, Piotr Dollar & Ron Appel. [pdollar-at-caltech.edu]
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice, this
14  * list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * The views and conclusions contained in the software and documentation are those
32  * of the authors and should not be interpreted as representing official policies,
33  * either expressed or implied, of the FreeBSD Project.
34  *
35  * hog.h
36  * Created on: Nov 30, 2012
37  * Derived from Piotr Dollar's MATLAB Image&Video Toolbox Version 3.00.
38  * Non-SSE version of the code provided by Matteo Munaro, Stefano Ghidoni and Stefano Michieletto
39  */
40 
41 #pragma once
42 
43 #include <pcl/pcl_macros.h> // export macro
44 
45 namespace pcl
46 {
47  namespace people
48  {
49  /** \brief @b HOG represents a class for computing the HOG descriptor described in
50  * Dalal, N. and Triggs, B., "Histograms of oriented gradients for human detection", CVPR 2005.
51  * \author Matteo Munaro, Stefano Ghidoni, Stefano Michieletto
52  * \ingroup people
53  */
55  {
56  public:
57 
58  /** \brief Constructor. */
59  HOG ();
60 
61  /** \brief Destructor. */
62  virtual ~HOG ();
63 
64  /**
65  * \brief Compute gradient magnitude and orientation at each location (uses sse).
66  *
67  * \param[in] I Image as array of float.
68  * \param[in] h Image height.
69  * \param[in] w Image width.
70  * \param[in] d Image number of channels.
71  * \param[out] M Gradient magnitude for each image point.
72  * \param[out] O Gradient orientation for each image point.
73  */
74  void
75  gradMag ( float *I, int h, int w, int d, float *M, float *O ) const;
76 
77  /**
78  * \brief Compute n_orients gradient histograms per bin_size x bin_size block of pixels.
79  *
80  * \param[in] M Gradient magnitude for each image point.
81  * \param[in] O Gradient orientation for each image point.
82  * \param[in] h Image height.
83  * \param[in] w Image width.
84  * \param[in] bin_size Spatial bin size.
85  * \param[in] n_orients Number of orientation bins.
86  * \param[in] soft_bin If true, each pixel can contribute to multiple spatial bins (using bilinear interpolation).
87  * \param[out] H Gradient histograms.
88  */
89  void
90  gradHist ( float *M, float *O, int h, int w, int bin_size, int n_orients, bool soft_bin, float *H) const;
91 
92  /**
93  * \brief Normalize histogram of gradients.
94  *
95  * \param[in] H Gradient histograms.
96  * \param[in] h Image height.
97  * \param[in] w Image width.
98  * \param[in] bin_size Spatial bin size.
99  * \param[in] n_orients Number of orientation bins.
100  * \param[in] clip Value at which to clip histogram bins.
101  * \param[out] G Normalized gradient histograms.
102  */
103  void
104  normalization ( float *H, int h, int w, int bin_size, int n_orients, float clip, float *G ) const;
105 
106  /**
107  * \brief Compute HOG descriptor.
108  *
109  * \param[in] I Image as array of float between 0 and 1.
110  * \param[in] h Image height.
111  * \param[in] w Image width.
112  * \param[in] n_channels Image number of channels.
113  * \param[in] bin_size Spatial bin size.
114  * \param[in] n_orients Number of orientation bins.
115  * \param[in] soft_bin If true, each pixel can contribute to multiple spatial bins (using bilinear interpolation).
116  * \param[out] descriptor HOG descriptor.
117  */
118  void
119  compute (float *I, int h, int w, int n_channels, int bin_size, int n_orients, bool soft_bin, float *descriptor);
120 
121  /**
122  * \brief Compute HOG descriptor with default parameters.
123  *
124  * \param[in] I Image as array of float between 0 and 1.
125  * \param[out] descriptor HOG descriptor.
126  */
127  void
128  compute (float *I, float *descriptor) const;
129 
130  private:
131 
132  /**
133  * \brief Compute x and y gradients for just one column (uses sse).
134  */
135  void
136  grad1 ( float *I, float *Gx, float *Gy, int h, int w, int x ) const;
137 
138  /**
139  * \brief Build lookup table a[] s.t. a[dx/2.02*n]~=acos(dx).
140  */
141  float*
142  acosTable () const;
143 
144  /**
145  * \brief Helper for gradHist, quantize O and M into O0, O1 and M0, M1 (uses sse).
146  */
147  void
148  gradQuantize ( float *O, float *M, int *O0, int *O1, float *M0, float *M1, int n_orients, int nb, int n, float norm ) const;
149 
150  /**
151  * \brief Platform independent aligned memory allocation (see also alFree).
152  */
153  void*
154  alMalloc ( std::size_t size, int alignment ) const;
155 
156  /**
157  * \brief Platform independent aligned memory de-allocation (see also alMalloc).
158  */
159  void
160  alFree (void* aligned) const;
161 
162  protected:
163 
164  /** \brief image height (default = 128) */
165  int h_;
166 
167  /** \brief image width (default = 64) */
168  int w_;
169 
170  /** \brief image number of channels (default = 3) */
172 
173  /** \brief spatial bin size (default = 8) */
174  int bin_size_;
175 
176  /** \brief number of orientation bins (default = 9) */
178 
179  /** \brief if true, each pixel can contribute to multiple spatial bins (using bilinear interpolation) (default = true) */
180  bool soft_bin_;
181 
182  /** \brief value at which to clip histogram bins (default = 0.2) */
183  float clip_;
184 
185  };
186  } /* namespace people */
187 } /* namespace pcl */
HOG represents a class for computing the HOG descriptor described in Dalal, N.
Definition: hog.h:55
int bin_size_
spatial bin size (default = 8)
Definition: hog.h:174
int n_orients_
number of orientation bins (default = 9)
Definition: hog.h:177
void gradMag(float *I, int h, int w, int d, float *M, float *O) const
Compute gradient magnitude and orientation at each location (uses sse).
int w_
image width (default = 64)
Definition: hog.h:168
void compute(float *I, float *descriptor) const
Compute HOG descriptor with default parameters.
float clip_
value at which to clip histogram bins (default = 0.2)
Definition: hog.h:183
int n_channels_
image number of channels (default = 3)
Definition: hog.h:171
virtual ~HOG()
Destructor.
void normalization(float *H, int h, int w, int bin_size, int n_orients, float clip, float *G) const
Normalize histogram of gradients.
void gradHist(float *M, float *O, int h, int w, int bin_size, int n_orients, bool soft_bin, float *H) const
Compute n_orients gradient histograms per bin_size x bin_size block of pixels.
bool soft_bin_
if true, each pixel can contribute to multiple spatial bins (using bilinear interpolation) (default =...
Definition: hog.h:180
void compute(float *I, int h, int w, int n_channels, int bin_size, int n_orients, bool soft_bin, float *descriptor)
Compute HOG descriptor.
HOG()
Constructor.
int h_
image height (default = 128)
Definition: hog.h:165
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:323