00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
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
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
00116
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
00134 CVAPI(void) cvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
00135 const CvArr* sum, const CvArr* sqsum,
00136 const CvArr* tilted_sum, double scale );
00137
00138
00139 CVAPI(int) cvRunHaarClassifierCascade( const CvHaarClassifierCascade* cascade,
00140 CvPoint pt, int start_stage CV_DEFAULT(0));
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 typedef struct
00152 {
00153 unsigned int x;
00154 unsigned int y;
00155 unsigned int l;
00156 } CvLSVMFilterPosition;
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
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
00186
00187
00188
00189
00190
00191
00192
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
00205
00206
00207
00208 typedef struct CvObjectDetection
00209 {
00210 CvRect rect;
00211 float score;
00212 } CvObjectDetection;
00213
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 CVAPI(CvLatentSvmDetector*) cvLoadLatentSvmDetector(const char* filename);
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 CVAPI(void) cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
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;
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