]> rtime.felk.cvut.cz Git - opencv.git/blob - opencv/include/opencv/cvaux.hpp
added Self-Similarity descriptor (thanks to Rainer Leinhart), fixed C++ sparse matric...
[opencv.git] / opencv / include / opencv / cvaux.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
4 //\r
5 //  By downloading, copying, installing or using the software you agree to this license.\r
6 //  If you do not agree to this license, do not download, install,\r
7 //  copy or use the software.\r
8 //\r
9 //\r
10 //                        Intel License Agreement\r
11 //                For Open Source Computer Vision Library\r
12 //\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.\r
14 // Third party copyrights are property of their respective owners.\r
15 //\r
16 // Redistribution and use in source and binary forms, with or without modification,\r
17 // are permitted provided that the following conditions are met:\r
18 //\r
19 //   * Redistribution's of source code must retain the above copyright notice,\r
20 //     this list of conditions and the following disclaimer.\r
21 //\r
22 //   * Redistribution's in binary form must reproduce the above copyright notice,\r
23 //     this list of conditions and the following disclaimer in the documentation\r
24 //     and/or other materials provided with the distribution.\r
25 //\r
26 //   * The name of Intel Corporation may not be used to endorse or promote products\r
27 //     derived from this software without specific prior written permission.\r
28 //\r
29 // This software is provided by the copyright holders and contributors "as is" and\r
30 // any express or implied warranties, including, but not limited to, the implied\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,\r
33 // indirect, incidental, special, exemplary, or consequential damages\r
34 // (including, but not limited to, procurement of substitute goods or services;\r
35 // loss of use, data, or profits; or business interruption) however caused\r
36 // and on any theory of liability, whether in contract, strict liability,\r
37 // or tort (including negligence or otherwise) arising in any way out of\r
38 // the use of this software, even if advised of the possibility of such damage.\r
39 //\r
40 //M*/\r
41 \r
42 #ifndef __CVAUX_HPP__\r
43 #define __CVAUX_HPP__\r
44 \r
45 #ifdef __cplusplus\r
46 \r
47 /****************************************************************************************\\r
48 *                                       CamShiftTracker                                  *\r
49 \****************************************************************************************/\r
50 \r
51 class CV_EXPORTS CvCamShiftTracker\r
52 {\r
53 public:\r
54 \r
55     CvCamShiftTracker();\r
56     virtual ~CvCamShiftTracker();\r
57 \r
58     /**** Characteristics of the object that are calculated by track_object method *****/\r
59     float   get_orientation() const // orientation of the object in degrees\r
60     { return m_box.angle; }\r
61     float   get_length() const // the larger linear size of the object\r
62     { return m_box.size.height; }\r
63     float   get_width() const // the smaller linear size of the object\r
64     { return m_box.size.width; }\r
65     CvPoint2D32f get_center() const // center of the object\r
66     { return m_box.center; }\r
67     CvRect get_window() const // bounding rectangle for the object\r
68     { return m_comp.rect; }\r
69 \r
70     /*********************** Tracking parameters ************************/\r
71     int     get_threshold() const // thresholding value that applied to back project\r
72     { return m_threshold; }\r
73 \r
74     int     get_hist_dims( int* dims = 0 ) const // returns number of histogram dimensions and sets\r
75     { return m_hist ? cvGetDims( m_hist->bins, dims ) : 0; }\r
76 \r
77     int     get_min_ch_val( int channel ) const // get the minimum allowed value of the specified channel\r
78     { return m_min_ch_val[channel]; }\r
79 \r
80     int     get_max_ch_val( int channel ) const // get the maximum allowed value of the specified channel\r
81     { return m_max_ch_val[channel]; }\r
82 \r
83     // set initial object rectangle (must be called before initial calculation of the histogram)\r
84     bool    set_window( CvRect window)\r
85     { m_comp.rect = window; return true; }\r
86 \r
87     bool    set_threshold( int threshold ) // threshold applied to the histogram bins\r
88     { m_threshold = threshold; return true; }\r
89 \r
90     bool    set_hist_bin_range( int dim, int min_val, int max_val );\r
91 \r
92     bool    set_hist_dims( int c_dims, int* dims );// set the histogram parameters\r
93 \r
94     bool    set_min_ch_val( int channel, int val ) // set the minimum allowed value of the specified channel\r
95     { m_min_ch_val[channel] = val; return true; }\r
96     bool    set_max_ch_val( int channel, int val ) // set the maximum allowed value of the specified channel\r
97     { m_max_ch_val[channel] = val; return true; }\r
98 \r
99     /************************ The processing methods *********************************/\r
100     // update object position\r
101     virtual bool  track_object( const IplImage* cur_frame );\r
102 \r
103     // update object histogram\r
104     virtual bool  update_histogram( const IplImage* cur_frame );\r
105 \r
106     // reset histogram\r
107     virtual void  reset_histogram();\r
108 \r
109     /************************ Retrieving internal data *******************************/\r
110     // get back project image\r
111     virtual IplImage* get_back_project()\r
112     { return m_back_project; }\r
113 \r
114     float query( int* bin ) const\r
115     { return m_hist ? (float)cvGetRealND(m_hist->bins, bin) : 0.f; }\r
116 \r
117 protected:\r
118 \r
119     // internal method for color conversion: fills m_color_planes group\r
120     virtual void color_transform( const IplImage* img );\r
121 \r
122     CvHistogram* m_hist;\r
123 \r
124     CvBox2D    m_box;\r
125     CvConnectedComp m_comp;\r
126 \r
127     float      m_hist_ranges_data[CV_MAX_DIM][2];\r
128     float*     m_hist_ranges[CV_MAX_DIM];\r
129 \r
130     int        m_min_ch_val[CV_MAX_DIM];\r
131     int        m_max_ch_val[CV_MAX_DIM];\r
132     int        m_threshold;\r
133 \r
134     IplImage*  m_color_planes[CV_MAX_DIM];\r
135     IplImage*  m_back_project;\r
136     IplImage*  m_temp;\r
137     IplImage*  m_mask;\r
138 };\r
139 \r
140 /****************************************************************************************\\r
141 *                                   Adaptive Skin Detector                               *\r
142 \****************************************************************************************/\r
143 \r
144 class CV_EXPORTS CvAdaptiveSkinDetector\r
145 {\r
146 private:\r
147         enum {\r
148                 GSD_HUE_LT = 3,\r
149                 GSD_HUE_UT = 33,\r
150                 GSD_INTENSITY_LT = 15,\r
151                 GSD_INTENSITY_UT = 250\r
152         };\r
153 \r
154         class CV_EXPORTS Histogram\r
155         {\r
156         private:\r
157                 enum {\r
158                         HistogramSize = (GSD_HUE_UT - GSD_HUE_LT + 1)\r
159                 };\r
160 \r
161         protected:\r
162                 int findCoverageIndex(double surfaceToCover, int defaultValue = 0);\r
163 \r
164         public:\r
165                 CvHistogram *fHistogram;\r
166                 Histogram();\r
167                 virtual ~Histogram();\r
168 \r
169                 void findCurveThresholds(int &x1, int &x2, double percent = 0.05);\r
170                 void mergeWith(Histogram *source, double weight);\r
171         };\r
172 \r
173         int nStartCounter, nFrameCount, nSkinHueLowerBound, nSkinHueUpperBound, nMorphingMethod, nSamplingDivider;\r
174         double fHistogramMergeFactor, fHuePercentCovered;\r
175         Histogram histogramHueMotion, skinHueHistogram;\r
176         IplImage *imgHueFrame, *imgSaturationFrame, *imgLastGrayFrame, *imgMotionFrame, *imgFilteredFrame;\r
177         IplImage *imgShrinked, *imgTemp, *imgGrayFrame, *imgHSVFrame;\r
178 \r
179 protected:\r
180         void initData(IplImage *src, int widthDivider, int heightDivider);\r
181         void adaptiveFilter();\r
182 \r
183 public:\r
184 \r
185         enum {\r
186                 MORPHING_METHOD_NONE = 0,\r
187                 MORPHING_METHOD_ERODE = 1,\r
188                 MORPHING_METHOD_ERODE_ERODE     = 2,\r
189                 MORPHING_METHOD_ERODE_DILATE = 3\r
190         };\r
191 \r
192         CvAdaptiveSkinDetector(int samplingDivider = 1, int morphingMethod = MORPHING_METHOD_NONE);\r
193         virtual ~CvAdaptiveSkinDetector();\r
194 \r
195         virtual void process(IplImage *inputBGRImage, IplImage *outputHueMask);\r
196 };\r
197 \r
198 \r
199 /****************************************************************************************\\r
200 *                                  Fuzzy MeanShift Tracker                               *\r
201 \****************************************************************************************/\r
202 \r
203 class CV_EXPORTS CvFuzzyPoint {\r
204 public:\r
205         double x, y, value;\r
206 \r
207         CvFuzzyPoint(double _x, double _y);\r
208 };\r
209 \r
210 class CV_EXPORTS CvFuzzyCurve {\r
211 private:\r
212     std::vector<CvFuzzyPoint> points;\r
213         double value, centre;\r
214 \r
215         bool between(double x, double x1, double x2);\r
216 \r
217 public:\r
218         CvFuzzyCurve();\r
219         ~CvFuzzyCurve();\r
220 \r
221         void setCentre(double _centre);\r
222         double getCentre();\r
223         void clear();\r
224         void addPoint(double x, double y);\r
225         double calcValue(double param);\r
226         double getValue();\r
227         void setValue(double _value);\r
228 };\r
229 \r
230 class CV_EXPORTS CvFuzzyFunction {\r
231 public:\r
232     std::vector<CvFuzzyCurve> curves;\r
233 \r
234         CvFuzzyFunction();\r
235         ~CvFuzzyFunction();\r
236         void addCurve(CvFuzzyCurve *curve, double value = 0);\r
237         void resetValues();\r
238         double calcValue();\r
239         CvFuzzyCurve *newCurve();\r
240 };\r
241 \r
242 class CV_EXPORTS CvFuzzyRule {\r
243 private:\r
244         CvFuzzyCurve *fuzzyInput1, *fuzzyInput2;\r
245         CvFuzzyCurve *fuzzyOutput;\r
246 public:\r
247         CvFuzzyRule();\r
248         ~CvFuzzyRule();\r
249         void setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1);\r
250         double calcValue(double param1, double param2);\r
251         CvFuzzyCurve *getOutputCurve();\r
252 };\r
253 \r
254 class CV_EXPORTS CvFuzzyController {\r
255 private:\r
256     std::vector<CvFuzzyRule*> rules;\r
257 public:\r
258         CvFuzzyController();\r
259         ~CvFuzzyController();\r
260         void addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1);\r
261         double calcOutput(double param1, double param2);\r
262 };\r
263 \r
264 class CV_EXPORTS CvFuzzyMeanShiftTracker\r
265 {\r
266 private:\r
267         class FuzzyResizer\r
268         {\r
269         private:\r
270                 CvFuzzyFunction iInput, iOutput;\r
271                 CvFuzzyController fuzzyController;\r
272         public:\r
273                 FuzzyResizer();\r
274                 int calcOutput(double edgeDensity, double density);\r
275         };\r
276 \r
277         class SearchWindow\r
278         {\r
279         public:\r
280                 FuzzyResizer *fuzzyResizer;\r
281                 int x, y;\r
282                 int width, height, maxWidth, maxHeight, ellipseHeight, ellipseWidth;\r
283                 int ldx, ldy, ldw, ldh, numShifts, numIters;\r
284                 int xGc, yGc;\r
285                 long m00, m01, m10, m11, m02, m20;\r
286                 double ellipseAngle;\r
287                 double density;\r
288                 unsigned int depthLow, depthHigh;\r
289                 int verticalEdgeLeft, verticalEdgeRight, horizontalEdgeTop, horizontalEdgeBottom;\r
290 \r
291                 SearchWindow();\r
292                 ~SearchWindow();\r
293                 void setSize(int _x, int _y, int _width, int _height);\r
294                 void initDepthValues(IplImage *maskImage, IplImage *depthMap);\r
295                 bool shift();\r
296                 void extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth);\r
297                 void getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);\r
298                 void getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);\r
299                 void getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);\r
300                 bool meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth);\r
301         };\r
302 \r
303 public:\r
304         enum TrackingState\r
305         {\r
306                 tsNone                  = 0,\r
307                 tsSearching     = 1,\r
308                 tsTracking              = 2,\r
309                 tsSetWindow     = 3,\r
310                 tsDisabled              = 10\r
311         };\r
312 \r
313         enum ResizeMethod {\r
314                 rmEdgeDensityLinear             = 0,\r
315                 rmEdgeDensityFuzzy              = 1,\r
316                 rmInnerDensity                  = 2\r
317         };\r
318 \r
319         enum {\r
320                 MinKernelMass                   = 1000\r
321         };\r
322 \r
323         SearchWindow kernel;\r
324         int searchMode;\r
325 \r
326 private:\r
327         enum\r
328         {\r
329                 MaxMeanShiftIteration   = 5,\r
330                 MaxSetSizeIteration     = 5\r
331         };\r
332 \r
333         void findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth);\r
334 \r
335 public:\r
336         CvFuzzyMeanShiftTracker();\r
337         ~CvFuzzyMeanShiftTracker();\r
338 \r
339         void track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass = MinKernelMass);\r
340 };\r
341 \r
342 \r
343 namespace cv\r
344 {\r
345 \r
346 class CV_EXPORTS OctTree\r
347 {\r
348 public:    \r
349     struct Node\r
350     {\r
351         Node() {}\r
352         int begin, end;\r
353         float x_min, x_max, y_min, y_max, z_min, z_max;         \r
354         int maxLevels;\r
355         bool isLeaf;\r
356         int children[8];\r
357     };\r
358 \r
359     OctTree();\r
360     OctTree( const Vector<Point3f>& points, int maxLevels = 10, int minPoints = 20 );\r
361     virtual ~OctTree();\r
362 \r
363     virtual void buildTree( const Vector<Point3f>& points, int maxLevels = 10, int minPoints = 20 );\r
364     virtual void getPointsWithinSphere( const Point3f& center, float radius,\r
365                                         Vector<Point3f>& points ) const;\r
366     const Vector<Node>& getNodes() const { return nodes; }\r
367 private:\r
368     int minPoints;\r
369     Vector<Point3f> points;\r
370     Vector<Node> nodes;\r
371         \r
372         virtual void buildNext(size_t node_ind);\r
373 };\r
374 \r
375 \r
376 CV_EXPORTS void computeNormals( const OctTree& octtree, \r
377                      const Vector<Point3f>& centers, \r
378                      Vector<Point3f>& normals, \r
379                      Vector<uchar>& mask, \r
380                      float normalRadius,\r
381                      int minNeighbors = 20);\r
382 \r
383 CV_EXPORTS void computeSpinImages( const OctTree& octtree, \r
384                         const Vector<Point3f>& points,\r
385                         const Vector<Point3f>& normals,\r
386                         Vector<uchar>& mask,\r
387                         Mat& spinImages,                                                  \r
388                         float support, \r
389                         float pixelsPerMeter );\r
390 \r
391 \r
392 /****************************************************************************************\\r
393 *            HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector        *\r
394 \****************************************************************************************/\r
395 \r
396 struct CV_EXPORTS HOGDescriptor\r
397 {\r
398 public:\r
399     enum { L2Hys=0 };\r
400 \r
401     HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),\r
402         cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),\r
403         histogramNormType(L2Hys), L2HysThreshold(0.2), gammaCorrection(true)\r
404     {}\r
405 \r
406     HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,\r
407         Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,\r
408         int _histogramNormType=L2Hys, double _L2HysThreshold=0.2, bool _gammaCorrection=false)\r
409         : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize),\r
410         nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma),\r
411         histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold),\r
412         gammaCorrection(_gammaCorrection)\r
413     {}\r
414 \r
415     HOGDescriptor(const String& filename)\r
416     {\r
417         load(filename);\r
418     }\r
419 \r
420     virtual ~HOGDescriptor() {}\r
421 \r
422     size_t getDescriptorSize() const;\r
423     bool checkDetectorSize() const;\r
424     double getWinSigma() const;\r
425 \r
426     virtual void setSVMDetector(const Vector<float>& _svmdetector);\r
427 \r
428     virtual bool load(const String& filename, const String& objname=String());\r
429     virtual void save(const String& filename, const String& objname=String()) const;\r
430 \r
431     virtual void compute(const Mat& img,\r
432                          Vector<float>& descriptors,\r
433                          Size winStride=Size(), Size padding=Size(),\r
434                          const Vector<Point>& locations=Vector<Point>()) const;\r
435     virtual void detect(const Mat& img, Vector<Point>& foundLocations,\r
436                         double hitThreshold=0, Size winStride=Size(),\r
437                         Size padding=Size(),\r
438                         const Vector<Point>& searchLocations=Vector<Point>()) const;\r
439     virtual void detectMultiScale(const Mat& img, Vector<Rect>& foundLocations,\r
440                                   double hitThreshold=0, Size winStride=Size(),\r
441                                   Size padding=Size(), double scale=1.05,\r
442                                   int groupThreshold=2) const;\r
443     virtual void computeGradient(const Mat& img, Mat& grad, Mat& angleOfs,\r
444                                  Size paddingTL=Size(), Size paddingBR=Size()) const;\r
445     virtual void normalizeBlockHistogram(Vector<float>& histogram) const;\r
446 \r
447     static Vector<float> getDefaultPeopleDetector();\r
448 \r
449     Size winSize;\r
450     Size blockSize;\r
451     Size blockStride;\r
452     Size cellSize;\r
453     int nbins;\r
454     int derivAperture;\r
455     double winSigma;\r
456     int histogramNormType;\r
457     double L2HysThreshold;\r
458     bool gammaCorrection;\r
459     Vector<float> svmDetector;\r
460 };\r
461 \r
462 \r
463 class CV_EXPORTS SelfSimDescriptor\r
464 {\r
465 public:\r
466     SelfSimDescriptor();\r
467     SelfSimDescriptor(int _ssize, int _lsize,\r
468         int _startDistanceBucket=DEFAULT_START_DISTANCE_BUCKET,\r
469         int _numberOfDistanceBuckets=DEFAULT_NUM_DISTANCE_BUCKETS,\r
470         int _nangles=DEFAULT_NUM_ANGLES);\r
471         SelfSimDescriptor(const SelfSimDescriptor& ss);\r
472         virtual ~SelfSimDescriptor();\r
473     SelfSimDescriptor& operator = (const SelfSimDescriptor& ss);\r
474 \r
475     size_t getDescriptorSize() const;\r
476     Size getGridSize( Size imgsize, Size winStride ) const;\r
477 \r
478     virtual void compute(const Mat& img, Vector<float>& descriptors, Size winStride=Size(),\r
479                          const Vector<Point>& locations=Vector<Point>()) const;\r
480     virtual void computeLogPolarMapping(Mat& mappingMask) const;\r
481     virtual void SSD(const Mat& img, Point pt, Mat& ssd) const;\r
482 \r
483         int smallSize;\r
484         int largeSize;\r
485     int startDistanceBucket;\r
486     int numberOfDistanceBuckets;\r
487     int numberOfAngles;\r
488 \r
489     enum { DEFAULT_SMALL_SIZE = 5, DEFAULT_LARGE_SIZE = 41,\r
490         DEFAULT_NUM_ANGLES = 20, DEFAULT_START_DISTANCE_BUCKET = 3,\r
491         DEFAULT_NUM_DISTANCE_BUCKETS = 7 };\r
492 };\r
493 \r
494     \r
495 class CV_EXPORTS PatchGenerator\r
496 {\r
497 public:\r
498     PatchGenerator();\r
499     PatchGenerator(double _backgroundMin, double _backgroundMax,\r
500                    double _noiseRange, bool _randomBlur=true,\r
501                    double _lambdaMin=0.6, double _lambdaMax=1.5,\r
502                    double _thetaMin=-CV_PI, double _thetaMax=CV_PI,\r
503                    double _phiMin=-CV_PI, double _phiMax=CV_PI );\r
504     void operator()(const Mat& image, Point2f pt, Mat& patch, Size patchSize, RNG& rng) const;\r
505     void operator()(const Mat& image, const Mat& transform, Mat& patch,\r
506                     Size patchSize, RNG& rng) const;\r
507     void warpWholeImage(const Mat& image, Mat& _T, Mat& buf,\r
508                         Mat& warped, int border, RNG& rng) const;\r
509     void generateRandomTransform(Point2f srcCenter, Point2f dstCenter,\r
510                                  Mat& transform, RNG& rng, bool inverse=false) const;\r
511     double backgroundMin, backgroundMax;\r
512     double noiseRange;\r
513     bool randomBlur;\r
514     double lambdaMin, lambdaMax;\r
515     double thetaMin, thetaMax;\r
516     double phiMin, phiMax;\r
517 };\r
518 \r
519 \r
520 class CV_EXPORTS LDetector\r
521 {\r
522 public:    \r
523     LDetector();\r
524     LDetector(int _radius, int _threshold, int _nOctaves,\r
525               int _nViews, double _baseFeatureSize, double _clusteringDistance);\r
526     void operator()(const Mat& image, Vector<Keypoint>& keypoints, int maxCount=0, bool scaleCoords=true) const;\r
527     void operator()(const Vector<Mat>& pyr, Vector<Keypoint>& keypoints, int maxCount=0, bool scaleCoords=true) const;\r
528     void getMostStable2D(const Mat& image, Vector<Keypoint>& keypoints,\r
529                          int maxCount, const PatchGenerator& patchGenerator) const;\r
530     void setVerbose(bool verbose);\r
531     \r
532     void read(const FileNode& node);\r
533     void write(FileStorage& fs, const String& name=String()) const;\r
534     \r
535     int radius;\r
536     int threshold;\r
537     int nOctaves;\r
538     int nViews;\r
539     bool verbose;\r
540     \r
541     double baseFeatureSize;\r
542     double clusteringDistance;\r
543 };\r
544 \r
545 \r
546 class CV_EXPORTS FernClassifier\r
547 {\r
548 public:\r
549     FernClassifier();\r
550     FernClassifier(const FileNode& node);\r
551     FernClassifier(const Vector<Point2f>& points,\r
552                    const Vector<Ptr<Mat> >& refimgs,\r
553                    const Vector<int>& labels=Vector<int>(),\r
554                    int _nclasses=0, int _patchSize=PATCH_SIZE,\r
555                    int _signatureSize=DEFAULT_SIGNATURE_SIZE,\r
556                    int _nstructs=DEFAULT_STRUCTS,\r
557                    int _structSize=DEFAULT_STRUCT_SIZE,\r
558                    int _nviews=DEFAULT_VIEWS,\r
559                    int _compressionMethod=COMPRESSION_NONE,\r
560                    const PatchGenerator& patchGenerator=PatchGenerator());\r
561     virtual ~FernClassifier();\r
562     virtual void read(const FileNode& n);\r
563     virtual void write(FileStorage& fs, const String& name=String()) const;\r
564     virtual void trainFromSingleView(const Mat& image,\r
565                                      const Vector<Keypoint>& keypoints,\r
566                                      int _patchSize=PATCH_SIZE,\r
567                                      int _signatureSize=DEFAULT_SIGNATURE_SIZE,\r
568                                      int _nstructs=DEFAULT_STRUCTS,\r
569                                      int _structSize=DEFAULT_STRUCT_SIZE,\r
570                                      int _nviews=DEFAULT_VIEWS,\r
571                                      int _compressionMethod=COMPRESSION_NONE,\r
572                                      const PatchGenerator& patchGenerator=PatchGenerator());\r
573     virtual void train(const Vector<Point2f>& points,\r
574                        const Vector<Ptr<Mat> >& refimgs,\r
575                        const Vector<int>& labels=Vector<int>(),\r
576                        int _nclasses=0, int _patchSize=PATCH_SIZE,\r
577                        int _signatureSize=DEFAULT_SIGNATURE_SIZE,\r
578                        int _nstructs=DEFAULT_STRUCTS,\r
579                        int _structSize=DEFAULT_STRUCT_SIZE,\r
580                        int _nviews=DEFAULT_VIEWS,\r
581                        int _compressionMethod=COMPRESSION_NONE,\r
582                        const PatchGenerator& patchGenerator=PatchGenerator());\r
583     virtual int operator()(const Mat& img, Point2f kpt, Vector<float>& signature) const;\r
584     virtual int operator()(const Mat& patch, Vector<float>& signature) const;\r
585     virtual void clear();\r
586     void setVerbose(bool verbose);\r
587     \r
588     int getClassCount() const;\r
589     int getStructCount() const;\r
590     int getStructSize() const;\r
591     int getSignatureSize() const;\r
592     int getCompressionMethod() const;\r
593     Size getPatchSize() const;    \r
594     \r
595     struct Feature\r
596     {\r
597         uchar x1, y1, x2, y2;\r
598         Feature() : x1(0), y1(0), x2(0), y2(0) {}\r
599         Feature(int _x1, int _y1, int _x2, int _y2)\r
600         : x1((uchar)_x1), y1((uchar)_y1), x2((uchar)_x2), y2((uchar)_y2)\r
601         {}\r
602         template<typename _Tp> bool operator ()(const Mat_<_Tp>& patch) const\r
603         { return patch(y1,x1) > patch(y2, x2); }\r
604     };\r
605     \r
606     enum\r
607     {\r
608         PATCH_SIZE = 31,\r
609         DEFAULT_STRUCTS = 50,\r
610         DEFAULT_STRUCT_SIZE = 9,\r
611         DEFAULT_VIEWS = 5000,\r
612         DEFAULT_SIGNATURE_SIZE = 176,\r
613         COMPRESSION_NONE = 0,\r
614         COMPRESSION_RANDOM_PROJ = 1,\r
615         COMPRESSION_PCA = 2,\r
616         DEFAULT_COMPRESSION_METHOD = COMPRESSION_NONE\r
617     };\r
618     \r
619 protected:\r
620     virtual void prepare(int _nclasses, int _patchSize, int _signatureSize,\r
621                          int _nstructs, int _structSize,\r
622                          int _nviews, int _compressionMethod);\r
623     virtual void finalize(RNG& rng);\r
624     virtual int getLeaf(int fidx, const Mat& patch) const;\r
625     \r
626     bool verbose;\r
627     int nstructs;\r
628     int structSize;\r
629     int nclasses;\r
630     int signatureSize;\r
631     int compressionMethod;\r
632     int leavesPerStruct;\r
633     Size patchSize;\r
634     Vector<Feature> features;\r
635     Vector<int> classCounters;\r
636     Vector<float> posteriors;\r
637 };\r
638 \r
639 class CV_EXPORTS PlanarObjectDetector\r
640 {\r
641 public:\r
642     PlanarObjectDetector();\r
643     PlanarObjectDetector(const FileNode& node);\r
644     PlanarObjectDetector(const Vector<Mat>& pyr, int _npoints=300,\r
645                          int _patchSize=FernClassifier::PATCH_SIZE,\r
646                          int _nstructs=FernClassifier::DEFAULT_STRUCTS,\r
647                          int _structSize=FernClassifier::DEFAULT_STRUCT_SIZE,\r
648                          int _nviews=FernClassifier::DEFAULT_VIEWS,\r
649                          const LDetector& detector=LDetector(),\r
650                          const PatchGenerator& patchGenerator=PatchGenerator()); \r
651     virtual ~PlanarObjectDetector();\r
652     virtual void train(const Vector<Mat>& pyr, int _npoints=300,\r
653                        int _patchSize=FernClassifier::PATCH_SIZE,\r
654                        int _nstructs=FernClassifier::DEFAULT_STRUCTS,\r
655                        int _structSize=FernClassifier::DEFAULT_STRUCT_SIZE,\r
656                        int _nviews=FernClassifier::DEFAULT_VIEWS,\r
657                        const LDetector& detector=LDetector(),\r
658                        const PatchGenerator& patchGenerator=PatchGenerator());\r
659     virtual void train(const Vector<Mat>& pyr, const Vector<Keypoint>& keypoints,\r
660                        int _patchSize=FernClassifier::PATCH_SIZE,\r
661                        int _nstructs=FernClassifier::DEFAULT_STRUCTS,\r
662                        int _structSize=FernClassifier::DEFAULT_STRUCT_SIZE,\r
663                        int _nviews=FernClassifier::DEFAULT_VIEWS,\r
664                        const LDetector& detector=LDetector(),\r
665                        const PatchGenerator& patchGenerator=PatchGenerator());\r
666     Rect getModelROI() const;\r
667     Vector<Keypoint> getModelPoints() const;\r
668     const LDetector& getDetector() const;\r
669     const FernClassifier& getClassifier() const;\r
670     void setVerbose(bool verbose);\r
671     \r
672     void read(const FileNode& node);\r
673     void write(FileStorage& fs, const String& name=String()) const;\r
674     bool operator()(const Mat& image, Mat& H, Vector<Point2f>& corners) const;\r
675     bool operator()(const Vector<Mat>& pyr, const Vector<Keypoint>& keypoints,\r
676                     Mat& H, Vector<Point2f>& corners, Vector<int>* pairs=0) const;\r
677     \r
678 protected:\r
679     bool verbose;\r
680     Rect modelROI;\r
681     Vector<Keypoint> modelPoints;\r
682     LDetector ldetector;\r
683     FernClassifier fernClassifier;\r
684 };\r
685     \r
686 }\r
687 \r
688 #endif /* __cplusplus */\r
689 \r
690 #endif /* __CVAUX_HPP__ */\r
691 \r
692 /* End of file. */\r