- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/opt/OpenCV-2.2.0/modules/objdetect/include/opencv2/objdetect/objdetect.hpp

Go to the documentation of this file.

    00001 /*M///////////////////////////////////////////////////////////////////////////////////////
    00002 //
    00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
    00004 //
    00005 //  By downloading, copying, installing or using the software you agree to this license.
    00006 //  If you do not agree to this license, do not download, install,
    00007 //  copy or use the software.
    00008 //
    00009 //
    00010 //                           License Agreement
    00011 //                For Open Source Computer Vision Library
    00012 //
    00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
    00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
    00015 // Third party copyrights are property of their respective owners.
    00016 //
    00017 // Redistribution and use in source and binary forms, with or without modification,
    00018 // are permitted provided that the following conditions are met:
    00019 //
    00020 //   * Redistribution's of source code must retain the above copyright notice,
    00021 //     this list of conditions and the following disclaimer.
    00022 //
    00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
    00024 //     this list of conditions and the following disclaimer in the documentation
    00025 //     and/or other materials provided with the distribution.
    00026 //
    00027 //   * The name of the copyright holders may not be used to endorse or promote products
    00028 //     derived from this software without specific prior written permission.
    00029 //
    00030 // This software is provided by the copyright holders and contributors "as is" and
    00031 // any express or implied warranties, including, but not limited to, the implied
    00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
    00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
    00034 // indirect, incidental, special, exemplary, or consequential damages
    00035 // (including, but not limited to, procurement of substitute goods or services;
    00036 // loss of use, data, or profits; or business interruption) however caused
    00037 // and on any theory of liability, whether in contract, strict liability,
    00038 // or tort (including negligence or otherwise) arising in any way out of
    00039 // the use of this software, even if advised of the possibility of such damage.
    00040 //
    00041 //M*/
    00042
    00043 #ifndef __OPENCV_OBJDETECT_HPP__
    00044 #define __OPENCV_OBJDETECT_HPP__
    00045
    00046 #include "opencv2/core/core.hpp"
    00047
    00048 #ifdef __cplusplus
    00049 extern "C" {
    00050 #endif
    00051
    00052 /****************************************************************************************\
    00053 *                         Haar-like Object Detection functions                           *
    00054 \****************************************************************************************/
    00055
    00056 #define CV_HAAR_MAGIC_VAL    0x42500000
    00057 #define CV_TYPE_NAME_HAAR    "opencv-haar-classifier"
    00058
    00059 #define CV_IS_HAAR_CLASSIFIER( haar )                                                    \
    00060     ((haar) != NULL &&                                                                   \
    00061     (((const CvHaarClassifierCascade*)(haar))->flags & CV_MAGIC_MASK)==CV_HAAR_MAGIC_VAL)
    00062
    00063 #define CV_HAAR_FEATURE_MAX  3
    00064
    00065 typedef struct CvHaarFeature
    00066 {
    00067     int  tilted;
    00068     struct
    00069     {
    00070         CvRect r;
    00071         float weight;
    00072     } rect[CV_HAAR_FEATURE_MAX];
    00073 } CvHaarFeature;
    00074
    00075 typedef struct CvHaarClassifier
    00076 {
    00077     int count;
    00078     CvHaarFeature* haar_feature;
    00079     float* threshold;
    00080     int* left;
    00081     int* right;
    00082     float* alpha;
    00083 } CvHaarClassifier;
    00084
    00085 typedef struct CvHaarStageClassifier
    00086 {
    00087     int  count;
    00088     float threshold;
    00089     CvHaarClassifier* classifier;
    00090
    00091     int next;
    00092     int child;
    00093     int parent;
    00094 } CvHaarStageClassifier;
    00095
    00096 typedef struct CvHidHaarClassifierCascade CvHidHaarClassifierCascade;
    00097
    00098 typedef struct CvHaarClassifierCascade
    00099 {
    00100     int  flags;
    00101     int  count;
    00102     CvSize orig_window_size;
    00103     CvSize real_window_size;
    00104     double scale;
    00105     CvHaarStageClassifier* stage_classifier;
    00106     CvHidHaarClassifierCascade* hid_cascade;
    00107 } CvHaarClassifierCascade;
    00108
    00109 typedef struct CvAvgComp
    00110 {
    00111     CvRect rect;
    00112     int neighbors;
    00113 } CvAvgComp;
    00114
    00115 /* Loads haar classifier cascade from a directory.
    00116    It is obsolete: convert your cascade to xml and use cvLoad instead */
    00117 CVAPI(CvHaarClassifierCascade*) cvLoadHaarClassifierCascade(
    00118                     const char* directory, CvSize orig_window_size);
    00119
    00120 CVAPI(void) cvReleaseHaarClassifierCascade( CvHaarClassifierCascade** cascade );
    00121
    00122 #define CV_HAAR_DO_CANNY_PRUNING    1
    00123 #define CV_HAAR_SCALE_IMAGE         2
    00124 #define CV_HAAR_FIND_BIGGEST_OBJECT 4
    00125 #define CV_HAAR_DO_ROUGH_SEARCH     8
    00126
    00127 CVAPI(CvSeq*) cvHaarDetectObjects( const CvArr* image,
    00128                      CvHaarClassifierCascade* cascade,
    00129                      CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
    00130                      int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
    00131                      CvSize min_size CV_DEFAULT(cvSize(0,0)), CvSize max_size CV_DEFAULT(cvSize(0,0)));
    00132
    00133 /* sets images for haar classifier cascade */
    00134 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
    00135                                                 const CvArr* sum, const CvArr* sqsum,
    00136                                                 const CvArr* tilted_sum, double scale );
    00137
    00138 /* runs the cascade on the specified window */
    00139 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
    00140                                        CvPoint pt, int start_stage CV_DEFAULT(0));
    00141
    00142
    00143 /****************************************************************************************\
    00144 *                         Latent SVM Object Detection functions                          *
    00145 \****************************************************************************************/
    00146
    00147 // DataType: STRUCT position
    00148 // Structure describes the position of the filter in the feature pyramid
    00149 // l - level in the feature pyramid
    00150 // (x, y) - coordinate in level l
    00151 typedef struct
    00152 {
    00153     unsigned int x;
    00154     unsigned int y;
    00155     unsigned int l;
    00156 } CvLSVMFilterPosition;
    00157
    00158 // DataType: STRUCT filterObject
    00159 // Description of the filter, which corresponds to the part of the object
    00160 // V               - ideal (penalty = 0) position of the partial filter
    00161 //                   from the root filter position (V_i in the paper)
    00162 // penaltyFunction - vector describes penalty function (d_i in the paper)
    00163 //                   pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2
    00164 // FILTER DESCRIPTION
    00165 //   Rectangular map (sizeX x sizeY),
    00166 //   every cell stores feature vector (dimension = p)
    00167 // H               - matrix of feature vectors
    00168 //                   to set and get feature vectors (i,j)
    00169 //                   used formula H[(j * sizeX + i) * p + k], where
    00170 //                   k - component of feature vector in cell (i, j)
    00171 // END OF FILTER DESCRIPTION
    00172 // xp              - auxillary parameter for internal use
    00173 //                   size of row in feature vectors
    00174 //                   (yp = (int) (p / xp); p = xp * yp)
    00175 typedef struct{
    00176     CvLSVMFilterPosition V;
    00177     float fineFunction[4];
    00178     unsigned int sizeX;
    00179     unsigned int sizeY;
    00180     unsigned int p;
    00181     unsigned int xp;
    00182     float *H;
    00183 } CvLSVMFilterObject;
    00184
    00185 // data type: STRUCT CvLatentSvmDetector
    00186 // structure contains internal representation of trained Latent SVM detector
    00187 // num_filters                  - total number of filters (root plus part) in model
    00188 // num_components               - number of components in model
    00189 // num_part_filters             - array containing number of part filters for each component
    00190 // filters                              - root and part filters for all model components
    00191 // b                                    - biases for all model components
    00192 // score_threshold              - confidence level threshold
    00193 typedef struct CvLatentSvmDetector
    00194 {
    00195         int num_filters;
    00196         int num_components;
    00197         int* num_part_filters;
    00198         CvLSVMFilterObject** filters;
    00199         float* b;
    00200         float score_threshold;
    00201 }
    00202 CvLatentSvmDetector;
    00203
    00204 // data type: STRUCT CvObjectDetection
    00205 // structure contains the bounding box and confidence level for detected object
    00206 // rect                                 - bounding box for a detected object
    00207 // score                                - confidence level
    00208 typedef struct CvObjectDetection
    00209 {
    00210         CvRect rect;
    00211         float score;
    00212 } CvObjectDetection;
    00213
    00215
    00216
    00217 /*
    00218 // load trained detector from a file
    00219 //
    00220 // API
    00221 // CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename);
    00222 // INPUT
    00223 // filename                             - path to the file containing the parameters of
    00224                                                 - trained Latent SVM detector
    00225 // OUTPUT
    00226 // trained Latent SVM detector in internal representation
    00227 */
    00228 CVAPI(CvLatentSvmDetector*) cvLoadLatentSvmDetector(const char* filename);
    00229
    00230 /*
    00231 // release memory allocated for CvLatentSvmDetector structure
    00232 //
    00233 // API
    00234 // void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
    00235 // INPUT
    00236 // detector                             - CvLatentSvmDetector structure to be released
    00237 // OUTPUT
    00238 */
    00239 CVAPI(void) cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
    00240
    00241 /*
    00242 // find rectangular regions in the given image that are likely
    00243 // to contain objects and corresponding confidence levels
    00244 //
    00245 // API
    00246 // CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
    00247 //                                                                      CvLatentSvmDetector* detector,
    00248 //                                                                      CvMemStorage* storage,
    00249 //                                                                      float overlap_threshold = 0.5f);
    00250 // INPUT
    00251 // image                                - image to detect objects in
    00252 // detector                             - Latent SVM detector in internal representation
    00253 // storage                              - memory storage to store the resultant sequence
    00254 //                                                      of the object candidate rectangles
    00255 // overlap_threshold    - threshold for the non-maximum suppression algorithm
    00256                            = 0.5f [here will be the reference to original paper]
    00257 // OUTPUT
    00258 // sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
    00259 */
    00260 CVAPI(CvSeq*) cvLatentSvmDetectObjects(IplImage* image,
    00261                                                                 CvLatentSvmDetector* detector,
    00262                                                                 CvMemStorage* storage,
    00263                                                                 float overlap_threshold CV_DEFAULT(0.5f));
    00264
    00265 #ifdef __cplusplus
    00266 }
    00267
    00268 namespace cv
    00269 {
    00270
    00272
    00273 CV_EXPORTS_W void groupRectangles(vector<Rect>& rectList, int groupThreshold, double eps=0.2);
    00274 CV_EXPORTS_W void groupRectangles(vector<Rect>& rectList, CV_OUT vector<int>& weights, int groupThreshold, double eps=0.2);
    00275
    00276 class CV_EXPORTS FeatureEvaluator
    00277 {
    00278 public:
    00279     enum { HAAR = 0, LBP = 1 };
    00280     virtual ~FeatureEvaluator();
    00281     virtual bool read(const FileNode& node);
    00282     virtual Ptr<FeatureEvaluator> clone() const;
    00283     virtual int getFeatureType() const;
    00284
    00285     virtual bool setImage(const Mat&, Size origWinSize);
    00286     virtual bool setWindow(Point p);
    00287
    00288     virtual double calcOrd(int featureIdx) const;
    00289     virtual int calcCat(int featureIdx) const;
    00290
    00291     static Ptr<FeatureEvaluator> create(int type);
    00292 };
    00293
    00294 template<> CV_EXPORTS void Ptr<CvHaarClassifierCascade>::delete_obj();
    00295
    00296 class CV_EXPORTS_W CascadeClassifier
    00297 {
    00298 public:
    00299     struct CV_EXPORTS DTreeNode
    00300     {
    00301         int featureIdx;
    00302         float threshold; // for ordered features only
    00303         int left;
    00304         int right;
    00305     };
    00306
    00307     struct CV_EXPORTS DTree
    00308     {
    00309         int nodeCount;
    00310     };
    00311
    00312     struct CV_EXPORTS Stage
    00313     {
    00314         int first;
    00315         int ntrees;
    00316         float threshold;
    00317     };
    00318
    00319     enum { BOOST = 0 };
    00320     enum { DO_CANNY_PRUNING = 1, SCALE_IMAGE = 2,
    00321            FIND_BIGGEST_OBJECT = 4, DO_ROUGH_SEARCH = 8 };
    00322
    00323     CV_WRAP CascadeClassifier();
    00324     CV_WRAP CascadeClassifier(const string& filename);
    00325     ~CascadeClassifier();
    00326
    00327     CV_WRAP bool empty() const;
    00328     CV_WRAP bool load(const string& filename);
    00329     bool read(const FileNode& node);
    00330     CV_WRAP void detectMultiScale( const Mat& image,
    00331                            CV_OUT vector<Rect>& objects,
    00332                            double scaleFactor=1.1,
    00333                            int minNeighbors=3, int flags=0,
    00334                            Size minSize=Size(),
    00335                            Size maxSize=Size());
    00336
    00337     bool setImage( Ptr<FeatureEvaluator>&, const Mat& );
    00338     int runAt( Ptr<FeatureEvaluator>&, Point );
    00339
    00340     bool is_stump_based;
    00341
    00342     int stageType;
    00343     int featureType;
    00344     int ncategories;
    00345     Size origWinSize;
    00346
    00347     vector<Stage> stages;
    00348     vector<DTree> classifiers;
    00349     vector<DTreeNode> nodes;
    00350     vector<float> leaves;
    00351     vector<int> subsets;
    00352
    00353     Ptr<FeatureEvaluator> feval;
    00354     Ptr<CvHaarClassifierCascade> oldCascade;
    00355 };
    00356
    00357
    00359
    00360 struct CV_EXPORTS_W HOGDescriptor
    00361 {
    00362 public:
    00363     enum { L2Hys=0 };
    00364     enum { DEFAULT_NLEVELS=64 };
    00365
    00366     CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
    00367         cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
    00368         histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true),
    00369         nlevels(HOGDescriptor::DEFAULT_NLEVELS)
    00370     {}
    00371
    00372     CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
    00373                   Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
    00374                   int _histogramNormType=HOGDescriptor::L2Hys,
    00375                   double _L2HysThreshold=0.2, bool _gammaCorrection=false,
    00376                   int _nlevels=HOGDescriptor::DEFAULT_NLEVELS)
    00377     : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize),
    00378     nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma),
    00379     histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold),
    00380     gammaCorrection(_gammaCorrection), nlevels(_nlevels)
    00381     {}
    00382
    00383     CV_WRAP HOGDescriptor(const String& filename)
    00384     {
    00385         load(filename);
    00386     }
    00387
    00388     HOGDescriptor(const HOGDescriptor& d)
    00389     {
    00390         d.copyTo(*this);
    00391     }
    00392
    00393     virtual ~HOGDescriptor() {}
    00394
    00395     CV_WRAP size_t getDescriptorSize() const;
    00396     CV_WRAP bool checkDetectorSize() const;
    00397     CV_WRAP double getWinSigma() const;
    00398
    00399     CV_WRAP virtual void setSVMDetector(const vector<float>& _svmdetector);
    00400
    00401     virtual bool read(FileNode& fn);
    00402     virtual void write(FileStorage& fs, const String& objname) const;
    00403
    00404     CV_WRAP virtual bool load(const String& filename, const String& objname=String());
    00405     CV_WRAP virtual void save(const String& filename, const String& objname=String()) const;
    00406     virtual void copyTo(HOGDescriptor& c) const;
    00407
    00408     CV_WRAP virtual void compute(const Mat& img,
    00409                          CV_OUT vector<float>& descriptors,
    00410                          Size winStride=Size(), Size padding=Size(),
    00411                          const vector<Point>& locations=vector<Point>()) const;
    00412     CV_WRAP virtual void detect(const Mat& img, CV_OUT vector<Point>& foundLocations,
    00413                         double hitThreshold=0, Size winStride=Size(),
    00414                         Size padding=Size(),
    00415                         const vector<Point>& searchLocations=vector<Point>()) const;
    00416     CV_WRAP virtual void detectMultiScale(const Mat& img, CV_OUT vector<Rect>& foundLocations,
    00417                                   double hitThreshold=0, Size winStride=Size(),
    00418                                   Size padding=Size(), double scale=1.05,
    00419                                   int groupThreshold=2) const;
    00420     CV_WRAP virtual void computeGradient(const Mat& img, CV_OUT Mat& grad, CV_OUT Mat& angleOfs,
    00421                                  Size paddingTL=Size(), Size paddingBR=Size()) const;
    00422
    00423     static vector<float> getDefaultPeopleDetector();
    00424
    00425     CV_PROP Size winSize;
    00426     CV_PROP Size blockSize;
    00427     CV_PROP Size blockStride;
    00428     CV_PROP Size cellSize;
    00429     CV_PROP int nbins;
    00430     CV_PROP int derivAperture;
    00431     CV_PROP double winSigma;
    00432     CV_PROP int histogramNormType;
    00433     CV_PROP double L2HysThreshold;
    00434     CV_PROP bool gammaCorrection;
    00435     CV_PROP vector<float> svmDetector;
    00436     CV_PROP int nlevels;
    00437 };
    00438
    00439
    00440 }
    00441
    00442 #endif
    00443
    00444 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines