Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

IntegralLBPExtraction.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 Pierre Moisan (Pierre.Moisan@USherbrooke.ca) 
00002 
00003    This library is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU Lesser General Public
00005    License as published by the Free Software Foundation; either
00006    version 2.1 of the License, or (at your option) any later version.
00007    
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Lesser General Public License for more details.
00012    
00013    You should have received a copy of the GNU Lesser General Public
00014    License along with this library; if not, write to the Free Software
00015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 */
00017 #ifndef _INTEGRALLBPEXTRACTION_H_
00018 #define _INTEGRALLBPEXTRACTION_H_
00019 
00020 #include "VisualFeaturesExtraction.h"
00021 #include "VisualIntegralDesc.h"
00022 #include "VisualTarget.h"
00023 #include <stdlib.h>
00024 #include <sys/timeb.h>
00025 
00026 namespace RobotFlow {
00027 //
00028 // Integral LBP (Lcoal Binary Pattern) Features Extraction for RobotFlow 
00029 //
00030 class IntegralLBPExtraction : public VisualFeaturesExtraction<double>
00031 { 
00032 public:
00033         //
00034         // Default constructor for Object 
00035         //
00036         IntegralLBPExtraction();
00037         
00038         //
00039         // Constructor with complete intialisation
00040         //
00041         IntegralLBPExtraction(int i_width, int i_height, 
00042                 int i_numChannels, int i_numHoriIntRect, int i_numVertIntRect,
00043                 int i_numSamples, int i_predicate, bool i_doInterpolation,
00044                 bool i_useUniform, int i_startAngle, double i_maxValue,
00045                 bool i_useRectDiff);
00046 
00047         //
00048         // BufferedNode constructor
00049         //
00050         IntegralLBPExtraction(std::string nodeName, FD::ParameterSet params);
00051 
00052         //
00053         // Constructor using input stream
00054         //
00055         IntegralLBPExtraction(std::istream &in)
00056         {
00057                 readFrom(in);
00058         }
00059         
00060         virtual ~IntegralLBPExtraction();
00061         
00062         // Default routine to print a IntegralLBPExtraction object to an output stream
00063         void printOn(std::ostream &out) const
00064         {
00065                 throw new FD::GeneralException("Exception in IntegralLBPExtraction::printOn: method not yet implemented.",__FILE__,__LINE__);
00066         }
00067 
00068         // Default routine to read a IntegralLBPExtraction object from an input stream
00069         void readFrom(std::istream &in)
00070         {
00071                 throw new FD::GeneralException("Exception in IntegralLBPExtraction::readFrom: method not yet implemented.",__FILE__,__LINE__);
00072         }
00073         
00074         virtual void request(int output_id, const FD::ParameterSet &req);
00075         
00076         void calculate(int output_id, int count, FD::Buffer &out);
00077         
00078         void Preprocess(IplImage *i_src);
00079         
00080         void ExtractFeatures(VisualROI *i_roi);
00081         
00082         void ExtractFeatures(IplImage *i_input, VisualROI *i_roi);
00083         
00084         VisualFeatureDesc<double> *GetDescriptor()
00085         {
00086                 return (*m_featVect)[0];
00087         }
00088         
00089         const VisualFeatureDesc<double> *GetCstDescriptor() const
00090         {
00091                 return (const VisualIntegralDesc<double> *)(*m_featVect)[0];
00092         }
00093 
00094 private:
00095         void Initialize();
00096         
00097         void InitSamplePoints();
00098         
00099         void ExtractLBPGeneralWithInterpolation(unsigned char *i_pixPtr);
00100         
00101         void ExtractLBPGeneralWithoutInterpolation(unsigned char *i_pixPtr);
00102         
00103         void ExtractLBPGeneralRIU2WithInterpolation(unsigned char *i_pixPtr);
00104         
00105         void ExtractLBPGeneralRIU2WithoutInterpolation(unsigned char *i_pixPtr);
00106         
00107         void ExtractLBP8WithInterpolation(unsigned char *i_pixPtr);
00108         
00109         void ExtractLBP8WithoutInterpolation(unsigned char *i_pixPtr);
00110         
00111         void ExtractLBP8RIU2WithInterpolation(unsigned char *i_pixPtr);
00112         
00113         void ExtractLBP8RIU2WithoutInterpolation(unsigned char *i_pixPtr);
00114         
00115         int ComputeBitTransitions(unsigned int i_val);
00116         
00117         int CountOneBits(unsigned int i_val);
00118 
00119 private:
00120         // Input IDs (for BufferedNode)
00121         int m_imageInID;
00122         int m_roiInID;
00123         int m_useNextImgInID;
00124         
00125         // Output IDs (for BufferedNode)
00126         int m_featuresOutID;
00127         int m_ppCompletedOutID;
00128         
00129         // Width of images
00130         int m_width;
00131         int m_imgSumWidth;
00132         // Height of images
00133         int m_height;
00134         // Number of channels in an image
00135         int m_numChannels;
00136         // Number of pixels in an image
00137         int m_numPixels;
00138         // Number of bytes in an image
00139         int m_numBytesInFrame;
00140         // Number of independant rectangular region to compute
00141         // the integral color features
00142         int m_numHoriIntRect;
00143         int m_numVertIntRect;
00144         int m_numIntRect;
00145         // The number of samples in the local neighborhood.
00146         int m_numSamples;
00147         // The current predicate (radius), i.e. the distance of the
00148         //  neighborhood from its center.
00149         int m_predicate;
00150         // Interpolation flag
00151         bool m_doInterpolation;
00152         // Flag to use only uniform patterns i.e. patterns with 2 or less
00153         //  bit transitions
00154         bool m_useUniform;
00155         // The angle of the first neighbor.
00156         int m_startAngle;
00157         // Maximum pixel channel value
00158         double m_maxValue;
00159         // Number of valid local binary patterns
00160         int m_numValidPattern;
00161         
00162         double m_maxFeatValue;
00163         
00164         bool m_useRectDiff;
00165         double *m_tmpMeanFeatures;
00166         double *m_curMeanVal;
00167         
00168         // Precalculated table of interpolation points.
00169         CvPoint *m_samplePoints;
00170         // Precalculated table of interpolation offsets.
00171         CvPoint2D32f *m_pointsOffsets;
00172         // Precalculated values for interpolation multiplication.
00173         double *m_BiLiMultipliers;
00174         // Temporary pixel pointers corresponding to the neighborhood samples
00175         unsigned char **m_tmpSamples;
00176         
00177         // Integral color descriptor for region of interest
00178         FD::RCPtr<FD::Vector<VisualFeatureDesc<double> *> > m_featVect;
00179         
00180         // Temporary image copy
00181         IplImage *m_curImage;
00182         // Grayscale version of current image
00183         IplImage *m_grayImage;
00184         // Each local pattern is an image
00185         IplImage **m_patternImage;
00186         // Pointer to channel image pixels
00187         unsigned char **m_patternPixPtr;
00188         int **m_sumPixPtr;
00189         // Sum of pixels (integral) image
00190         IplImage **m_sumImage;
00191         
00192         // Function pointer to the appropriate private extraction routine
00193         void (IntegralLBPExtraction::*m_extractionFct)(unsigned char *);
00194 };
00195 
00196 }
00197 
00198 #endif

Generated on Wed Oct 5 14:36:12 2005 for RobotFlow by  doxygen 1.4.4