Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/people/include/pcl/people/hog.h
00001 /*
00002  * Software License Agreement (Simplified BSD License)
00003  *
00004  * Point Cloud Library (PCL) - www.pointclouds.org
00005  * Copyright (c) 2013-, Open Perception, Inc.
00006  * Copyright (c) 2012, Piotr Dollar & Ron Appel.  [pdollar-at-caltech.edu]
00007  *
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions are met: 
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice, this
00014  *    list of conditions and the following disclaimer.
00015  *
00016  * 2. Redistributions in binary form must reproduce the above copyright notice,
00017  *    this list of conditions and the following disclaimer in the documentation
00018  *    and/or other materials provided with the distribution. 
00019  * 
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00024  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  * The views and conclusions contained in the software and documentation are those
00032  * of the authors and should not be interpreted as representing official policies,
00033  * either expressed or implied, of the FreeBSD Project.
00034  *
00035  * hog.h
00036  * Created on: Nov 30, 2012
00037  * Derived from Piotr Dollar's MATLAB Image&Video Toolbox      Version 3.00. 
00038  * Non-SSE version of the code provided by Matteo Munaro, Stefano Ghidoni and Stefano Michieletto
00039  */
00040 
00041 #ifndef PCL_PEOPLE_HOG_H_
00042 #define PCL_PEOPLE_HOG_H_
00043 
00044 #include <pcl/pcl_macros.h>
00045 
00046 namespace pcl
00047 { 
00048   namespace people
00049   {
00050     /** \brief @b HOG represents a class for computing the HOG descriptor described in 
00051       * Dalal, N. and Triggs, B., "Histograms of oriented gradients for human detection", CVPR 2005.
00052       * \author Matteo Munaro, Stefano Ghidoni, Stefano Michieletto
00053       * \ingroup people
00054       */
00055     class PCL_EXPORTS HOG
00056     {
00057     public:
00058 
00059       /** \brief Constructor. */
00060       HOG ();
00061 
00062       /** \brief Destructor. */
00063       virtual ~HOG ();
00064       
00065       /** 
00066        * \brief Compute gradient magnitude and orientation at each location (uses sse). 
00067        * 
00068        * \param[in] I Image as array of float.
00069        * \param[in] h Image height.
00070        * \param[in] w Image width.
00071        * \param[in] d Image number of channels.
00072        * \param[out] M Gradient magnitude for each image point.
00073        * \param[out] O Gradient orientation for each image point.
00074        */
00075       void 
00076       gradMag ( float *I, int h, int w, int d, float *M, float *O ) const;
00077 
00078       /** 
00079        * \brief Compute n_orients gradient histograms per bin_size x bin_size block of pixels.  
00080        * 
00081        * \param[in] M Gradient magnitude for each image point.
00082        * \param[in] O Gradient orientation for each image point.
00083        * \param[in] h Image height.
00084        * \param[in] w Image width.
00085        * \param[in] bin_size Spatial bin size.
00086        * \param[in] n_orients Number of orientation bins.
00087        * \param[in] soft_bin If true, each pixel can contribute to multiple spatial bins (using bilinear interpolation).
00088        * \param[out] H Gradient histograms.
00089        */
00090       void 
00091       gradHist ( float *M, float *O, int h, int w, int bin_size, int n_orients, bool soft_bin, float *H) const;
00092       
00093       /** 
00094        * \brief Normalize histogram of gradients. 
00095        * 
00096        * \param[in] H Gradient histograms.
00097        * \param[in] h Image height.
00098        * \param[in] w Image width.
00099        * \param[in] bin_size Spatial bin size.
00100        * \param[in] n_orients Number of orientation bins.  
00101        * \param[in] clip Value at which to clip histogram bins.      
00102        * \param[out] G Normalized gradient histograms.
00103        */
00104       void 
00105       normalization ( float *H, int h, int w, int bin_size, int n_orients, float clip, float *G ) const;
00106       
00107       /**
00108        * \brief Compute HOG descriptor.
00109        * 
00110        * \param[in] I Image as array of float between 0 and 1.
00111        * \param[in] h Image height.
00112        * \param[in] w Image width.
00113        * \param[in] n_channels Image number of channels.
00114        * \param[in] bin_size Spatial bin size.  
00115        * \param[in] n_orients Number of orientation bins.     
00116        * \param[in] soft_bin If true, each pixel can contribute to multiple spatial bins (using bilinear interpolation).
00117        * \param[out] descriptor HOG descriptor.
00118        */
00119       void
00120       compute (float *I, int h, int w, int n_channels, int bin_size, int n_orients, bool soft_bin, float *descriptor);
00121       
00122       /**
00123        * \brief Compute HOG descriptor with default parameters.
00124        * 
00125        * \param[in] I Image as array of float between 0 and 1.
00126        * \param[out] descriptor HOG descriptor.
00127        */
00128       void
00129       compute (float *I, float *descriptor) const;
00130       
00131         private:
00132     
00133       /** 
00134        * \brief Compute x and y gradients for just one column (uses sse). 
00135        */
00136       void 
00137       grad1 ( float *I, float *Gx, float *Gy, int h, int w, int x ) const; 
00138       
00139       /** 
00140        * \brief Build lookup table a[] s.t. a[dx/2.02*n]~=acos(dx). 
00141        */
00142       float* 
00143       acosTable () const;
00144       
00145       /** 
00146        * \brief Helper for gradHist, quantize O and M into O0, O1 and M0, M1 (uses sse). 
00147        */
00148       void 
00149       gradQuantize ( float *O, float *M, int *O0, int *O1, float *M0, float *M1, int n_orients, int nb, int n, float norm ) const;
00150       
00151       /** 
00152        * \brief Platform independent aligned memory allocation (see also alFree).
00153        */ 
00154       void* 
00155       alMalloc ( size_t size, int alignment ) const;
00156       
00157       /** 
00158        * \brief Platform independent aligned memory de-allocation (see also alMalloc).
00159        */ 
00160       void 
00161       alFree (void* aligned) const;
00162       
00163     protected:
00164       
00165       /** \brief image height (default = 128) */
00166       int h_;
00167       
00168       /** \brief image width (default = 64) */
00169       int w_;
00170       
00171       /** \brief image number of channels (default = 3) */
00172       int n_channels_;
00173       
00174       /** \brief spatial bin size (default = 8) */
00175       int bin_size_; 
00176       
00177       /** \brief number of orientation bins (default = 9) */
00178       int n_orients_;
00179       
00180       /** \brief if true, each pixel can contribute to multiple spatial bins (using bilinear interpolation) (default = true) */
00181       bool soft_bin_;   
00182       
00183       /** \brief value at which to clip histogram bins (default = 0.2) */
00184       float clip_; 
00185       
00186     };
00187   } /* namespace people */
00188 } /* namespace pcl */
00189 #endif /* PCL_PEOPLE_HOG_H_ */