1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\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
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\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
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\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
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
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
42 #ifndef __CVAUX_HPP__
\r
43 #define __CVAUX_HPP__
\r
49 /****************************************************************************************\
\r
51 \****************************************************************************************/
\r
53 class CV_EXPORTS CvCamShiftTracker
\r
57 CvCamShiftTracker();
\r
58 virtual ~CvCamShiftTracker();
\r
60 /**** Characteristics of the object that are calculated by track_object method *****/
\r
61 float get_orientation() const // orientation of the object in degrees
\r
62 { return m_box.angle; }
\r
63 float get_length() const // the larger linear size of the object
\r
64 { return m_box.size.height; }
\r
65 float get_width() const // the smaller linear size of the object
\r
66 { return m_box.size.width; }
\r
67 CvPoint2D32f get_center() const // center of the object
\r
68 { return m_box.center; }
\r
69 CvRect get_window() const // bounding rectangle for the object
\r
70 { return m_comp.rect; }
\r
72 /*********************** Tracking parameters ************************/
\r
73 int get_threshold() const // thresholding value that applied to back project
\r
74 { return m_threshold; }
\r
76 int get_hist_dims( int* dims = 0 ) const // returns number of histogram dimensions and sets
\r
77 { return m_hist ? cvGetDims( m_hist->bins, dims ) : 0; }
\r
79 int get_min_ch_val( int channel ) const // get the minimum allowed value of the specified channel
\r
80 { return m_min_ch_val[channel]; }
\r
82 int get_max_ch_val( int channel ) const // get the maximum allowed value of the specified channel
\r
83 { return m_max_ch_val[channel]; }
\r
85 // set initial object rectangle (must be called before initial calculation of the histogram)
\r
86 bool set_window( CvRect window)
\r
87 { m_comp.rect = window; return true; }
\r
89 bool set_threshold( int threshold ) // threshold applied to the histogram bins
\r
90 { m_threshold = threshold; return true; }
\r
92 bool set_hist_bin_range( int dim, int min_val, int max_val );
\r
94 bool set_hist_dims( int c_dims, int* dims );// set the histogram parameters
\r
96 bool set_min_ch_val( int channel, int val ) // set the minimum allowed value of the specified channel
\r
97 { m_min_ch_val[channel] = val; return true; }
\r
98 bool set_max_ch_val( int channel, int val ) // set the maximum allowed value of the specified channel
\r
99 { m_max_ch_val[channel] = val; return true; }
\r
101 /************************ The processing methods *********************************/
\r
102 // update object position
\r
103 virtual bool track_object( const IplImage* cur_frame );
\r
105 // update object histogram
\r
106 virtual bool update_histogram( const IplImage* cur_frame );
\r
109 virtual void reset_histogram();
\r
111 /************************ Retrieving internal data *******************************/
\r
112 // get back project image
\r
113 virtual IplImage* get_back_project()
\r
114 { return m_back_project; }
\r
116 float query( int* bin ) const
\r
117 { return m_hist ? (float)cvGetRealND(m_hist->bins, bin) : 0.f; }
\r
121 // internal method for color conversion: fills m_color_planes group
\r
122 virtual void color_transform( const IplImage* img );
\r
124 CvHistogram* m_hist;
\r
127 CvConnectedComp m_comp;
\r
129 float m_hist_ranges_data[CV_MAX_DIM][2];
\r
130 float* m_hist_ranges[CV_MAX_DIM];
\r
132 int m_min_ch_val[CV_MAX_DIM];
\r
133 int m_max_ch_val[CV_MAX_DIM];
\r
136 IplImage* m_color_planes[CV_MAX_DIM];
\r
137 IplImage* m_back_project;
\r
142 /****************************************************************************************\
\r
143 * Adaptive Skin Detector *
\r
144 \****************************************************************************************/
\r
146 class CV_EXPORTS CvAdaptiveSkinDetector
\r
152 GSD_INTENSITY_LT = 15,
\r
153 GSD_INTENSITY_UT = 250
\r
156 class CV_EXPORTS Histogram
\r
160 HistogramSize = (GSD_HUE_UT - GSD_HUE_LT + 1)
\r
164 int findCoverageIndex(double surfaceToCover, int defaultValue = 0);
\r
167 CvHistogram *fHistogram;
\r
169 virtual ~Histogram();
\r
171 void findCurveThresholds(int &x1, int &x2, double percent = 0.05);
\r
172 void mergeWith(Histogram *source, double weight);
\r
175 int nStartCounter, nFrameCount, nSkinHueLowerBound, nSkinHueUpperBound, nMorphingMethod, nSamplingDivider;
\r
176 double fHistogramMergeFactor, fHuePercentCovered;
\r
177 Histogram histogramHueMotion, skinHueHistogram;
\r
178 IplImage *imgHueFrame, *imgSaturationFrame, *imgLastGrayFrame, *imgMotionFrame, *imgFilteredFrame;
\r
179 IplImage *imgShrinked, *imgTemp, *imgGrayFrame, *imgHSVFrame;
\r
182 void initData(IplImage *src, int widthDivider, int heightDivider);
\r
183 void adaptiveFilter();
\r
188 MORPHING_METHOD_NONE = 0,
\r
189 MORPHING_METHOD_ERODE = 1,
\r
190 MORPHING_METHOD_ERODE_ERODE = 2,
\r
191 MORPHING_METHOD_ERODE_DILATE = 3
\r
194 CvAdaptiveSkinDetector(int samplingDivider = 1, int morphingMethod = MORPHING_METHOD_NONE);
\r
195 virtual ~CvAdaptiveSkinDetector();
\r
197 virtual void process(IplImage *inputBGRImage, IplImage *outputHueMask);
\r
201 /****************************************************************************************\
\r
202 * Fuzzy MeanShift Tracker *
\r
203 \****************************************************************************************/
\r
205 class CV_EXPORTS CvFuzzyPoint {
\r
207 double x, y, value;
\r
209 CvFuzzyPoint(double _x, double _y);
\r
212 class CV_EXPORTS CvFuzzyCurve {
\r
214 std::vector<CvFuzzyPoint> points;
\r
215 double value, centre;
\r
217 bool between(double x, double x1, double x2);
\r
223 void setCentre(double _centre);
\r
224 double getCentre();
\r
226 void addPoint(double x, double y);
\r
227 double calcValue(double param);
\r
229 void setValue(double _value);
\r
232 class CV_EXPORTS CvFuzzyFunction {
\r
234 std::vector<CvFuzzyCurve> curves;
\r
237 ~CvFuzzyFunction();
\r
238 void addCurve(CvFuzzyCurve *curve, double value = 0);
\r
239 void resetValues();
\r
240 double calcValue();
\r
241 CvFuzzyCurve *newCurve();
\r
244 class CV_EXPORTS CvFuzzyRule {
\r
246 CvFuzzyCurve *fuzzyInput1, *fuzzyInput2;
\r
247 CvFuzzyCurve *fuzzyOutput;
\r
251 void setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1);
\r
252 double calcValue(double param1, double param2);
\r
253 CvFuzzyCurve *getOutputCurve();
\r
256 class CV_EXPORTS CvFuzzyController {
\r
258 std::vector<CvFuzzyRule*> rules;
\r
260 CvFuzzyController();
\r
261 ~CvFuzzyController();
\r
262 void addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1);
\r
263 double calcOutput(double param1, double param2);
\r
266 class CV_EXPORTS CvFuzzyMeanShiftTracker
\r
272 CvFuzzyFunction iInput, iOutput;
\r
273 CvFuzzyController fuzzyController;
\r
276 int calcOutput(double edgeDensity, double density);
\r
282 FuzzyResizer *fuzzyResizer;
\r
284 int width, height, maxWidth, maxHeight, ellipseHeight, ellipseWidth;
\r
285 int ldx, ldy, ldw, ldh, numShifts, numIters;
\r
287 long m00, m01, m10, m11, m02, m20;
\r
288 double ellipseAngle;
\r
290 unsigned int depthLow, depthHigh;
\r
291 int verticalEdgeLeft, verticalEdgeRight, horizontalEdgeTop, horizontalEdgeBottom;
\r
295 void setSize(int _x, int _y, int _width, int _height);
\r
296 void initDepthValues(IplImage *maskImage, IplImage *depthMap);
\r
298 void extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth);
\r
299 void getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);
\r
300 void getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);
\r
301 void getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);
\r
302 bool meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth);
\r
315 enum ResizeMethod {
\r
316 rmEdgeDensityLinear = 0,
\r
317 rmEdgeDensityFuzzy = 1,
\r
322 MinKernelMass = 1000
\r
325 SearchWindow kernel;
\r
331 MaxMeanShiftIteration = 5,
\r
332 MaxSetSizeIteration = 5
\r
335 void findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth);
\r
338 CvFuzzyMeanShiftTracker();
\r
339 ~CvFuzzyMeanShiftTracker();
\r
341 void track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass = MinKernelMass);
\r
348 class CV_EXPORTS OctTree
\r
355 float x_min, x_max, y_min, y_max, z_min, z_max;
\r
362 OctTree( const Vector<Point3f>& points, int maxLevels = 10, int minPoints = 20 );
\r
363 virtual ~OctTree();
\r
365 virtual void buildTree( const Vector<Point3f>& points, int maxLevels = 10, int minPoints = 20 );
\r
366 virtual void getPointsWithinSphere( const Point3f& center, float radius,
\r
367 Vector<Point3f>& points ) const;
\r
368 const Vector<Node>& getNodes() const { return nodes; }
\r
371 Vector<Point3f> points;
\r
372 Vector<Node> nodes;
\r
374 virtual void buildNext(size_t node_ind);
\r
378 class CV_EXPORTS Mesh3D
\r
381 struct EmptyMeshException {};
\r
384 Mesh3D(const Vector<Point3f>& vtx);
\r
387 void buildOctTree();
\r
388 void clearOctTree();
\r
389 float estimateResolution(float tryRatio = 0.1f);
\r
390 void computeNormals(float normalRadius, int minNeighbors = 20);
\r
391 void computeNormals(const Vector<int>& subset, float normalRadius, int minNeighbors = 20);
\r
393 void writeAsVrml(const String& file, const Vector<Scalar>& colors = Vector<Scalar>()) const;
\r
395 Vector<Point3f> vtx;
\r
396 Vector<Point3f> normals;
\r
400 const static Point3f allzero;
\r
403 class CV_EXPORTS SpinImageModel
\r
407 /* model parameters, leave unset for default or auto estimate */
\r
408 float normalRadius;
\r
418 /* public interface */
\r
420 explicit SpinImageModel(const Mesh3D& mesh);
\r
423 void setLogger(std::ostream* log);
\r
424 void selectRandomSubset(float ratio);
\r
427 Vector< Vector< Vec2i > > match(const SpinImageModel& scene);
\r
429 Mat packRandomScaledSpins(bool separateScale = false, size_t xCount = 10, size_t yCount = 10) const;
\r
431 size_t getSpinCount() const { return spinImages.rows; }
\r
432 Mat getSpinImage(size_t index) const { return spinImages.row(index); }
\r
433 const Point3f& getSpinVertex(size_t index) const { return mesh.vtx[subset[index]]; }
\r
434 const Point3f& getSpinNormal(size_t index) const { return mesh.normals[subset[index]]; }
\r
436 const Mesh3D& getMesh() const { return mesh; }
\r
438 /* static utility functions */
\r
439 static bool spinCorrelation(const Mat& spin1, const Mat& spin2, float lambda, float& result);
\r
441 static Point2f calcSpinMapCoo(const Point3f& point, const Point3f& vertex, const Point3f& normal);
\r
443 static float geometricConsistency(const Point3f& pointScene1, const Point3f& normalScene1,
\r
444 const Point3f& pointModel1, const Point3f& normalModel1,
\r
445 const Point3f& pointScene2, const Point3f& normalScene2,
\r
446 const Point3f& pointModel2, const Point3f& normalModel2);
\r
448 static float groupingCreteria(const Point3f& pointScene1, const Point3f& normalScene1,
\r
449 const Point3f& pointModel1, const Point3f& normalModel1,
\r
450 const Point3f& pointScene2, const Point3f& normalScene2,
\r
451 const Point3f& pointModel2, const Point3f& normalModel2,
\r
454 void defaultParams();
\r
456 void matchSpinToModel(const Mat& spin, Vector<int>& indeces,
\r
457 Vector<float>& corrCoeffs, bool useExtremeOutliers = true) const;
\r
459 void repackSpinImages(const Vector<uchar>& mask, Mat& spinImages, bool reAlloc = true) const;
\r
461 Vector<int> subset;
\r
467 class CV_EXPORTS TickMeter
\r
474 int64 getTimeTicks() const;
\r
475 double getTimeMicro() const;
\r
476 double getTimeMilli() const;
\r
477 double getTimeSec() const;
\r
478 int64 getCounter() const;
\r
487 CV_EXPORTS std::ostream& operator<<(std::ostream& out, const TickMeter& tm);
\r
489 /****************************************************************************************\
\r
490 * HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector *
\r
491 \****************************************************************************************/
\r
493 struct CV_EXPORTS HOGDescriptor
\r
498 HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
\r
499 cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
\r
500 histogramNormType(L2Hys), L2HysThreshold(0.2), gammaCorrection(true)
\r
503 HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
\r
504 Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
\r
505 int _histogramNormType=L2Hys, double _L2HysThreshold=0.2, bool _gammaCorrection=false)
\r
506 : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize),
\r
507 nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma),
\r
508 histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold),
\r
509 gammaCorrection(_gammaCorrection)
\r
512 HOGDescriptor(const String& filename)
\r
517 virtual ~HOGDescriptor() {}
\r
519 size_t getDescriptorSize() const;
\r
520 bool checkDetectorSize() const;
\r
521 double getWinSigma() const;
\r
523 virtual void setSVMDetector(const Vector<float>& _svmdetector);
\r
525 virtual bool load(const String& filename, const String& objname=String());
\r
526 virtual void save(const String& filename, const String& objname=String()) const;
\r
528 virtual void compute(const Mat& img,
\r
529 Vector<float>& descriptors,
\r
530 Size winStride=Size(), Size padding=Size(),
\r
531 const Vector<Point>& locations=Vector<Point>()) const;
\r
532 virtual void detect(const Mat& img, Vector<Point>& foundLocations,
\r
533 double hitThreshold=0, Size winStride=Size(),
\r
534 Size padding=Size(),
\r
535 const Vector<Point>& searchLocations=Vector<Point>()) const;
\r
536 virtual void detectMultiScale(const Mat& img, Vector<Rect>& foundLocations,
\r
537 double hitThreshold=0, Size winStride=Size(),
\r
538 Size padding=Size(), double scale=1.05,
\r
539 int groupThreshold=2) const;
\r
540 virtual void computeGradient(const Mat& img, Mat& grad, Mat& angleOfs,
\r
541 Size paddingTL=Size(), Size paddingBR=Size()) const;
\r
542 virtual void normalizeBlockHistogram(Vector<float>& histogram) const;
\r
544 static Vector<float> getDefaultPeopleDetector();
\r
553 int histogramNormType;
\r
554 double L2HysThreshold;
\r
555 bool gammaCorrection;
\r
556 Vector<float> svmDetector;
\r
560 class CV_EXPORTS SelfSimDescriptor
\r
563 SelfSimDescriptor();
\r
564 SelfSimDescriptor(int _ssize, int _lsize,
\r
565 int _startDistanceBucket=DEFAULT_START_DISTANCE_BUCKET,
\r
566 int _numberOfDistanceBuckets=DEFAULT_NUM_DISTANCE_BUCKETS,
\r
567 int _nangles=DEFAULT_NUM_ANGLES);
\r
568 SelfSimDescriptor(const SelfSimDescriptor& ss);
\r
569 virtual ~SelfSimDescriptor();
\r
570 SelfSimDescriptor& operator = (const SelfSimDescriptor& ss);
\r
572 size_t getDescriptorSize() const;
\r
573 Size getGridSize( Size imgsize, Size winStride ) const;
\r
575 virtual void compute(const Mat& img, Vector<float>& descriptors, Size winStride=Size(),
\r
576 const Vector<Point>& locations=Vector<Point>()) const;
\r
577 virtual void computeLogPolarMapping(Mat& mappingMask) const;
\r
578 virtual void SSD(const Mat& img, Point pt, Mat& ssd) const;
\r
582 int startDistanceBucket;
\r
583 int numberOfDistanceBuckets;
\r
584 int numberOfAngles;
\r
586 enum { DEFAULT_SMALL_SIZE = 5, DEFAULT_LARGE_SIZE = 41,
\r
587 DEFAULT_NUM_ANGLES = 20, DEFAULT_START_DISTANCE_BUCKET = 3,
\r
588 DEFAULT_NUM_DISTANCE_BUCKETS = 7 };
\r
592 class CV_EXPORTS PatchGenerator
\r
596 PatchGenerator(double _backgroundMin, double _backgroundMax,
\r
597 double _noiseRange, bool _randomBlur=true,
\r
598 double _lambdaMin=0.6, double _lambdaMax=1.5,
\r
599 double _thetaMin=-CV_PI, double _thetaMax=CV_PI,
\r
600 double _phiMin=-CV_PI, double _phiMax=CV_PI );
\r
601 void operator()(const Mat& image, Point2f pt, Mat& patch, Size patchSize, RNG& rng) const;
\r
602 void operator()(const Mat& image, const Mat& transform, Mat& patch,
\r
603 Size patchSize, RNG& rng) const;
\r
604 void warpWholeImage(const Mat& image, Mat& _T, Mat& buf,
\r
605 Mat& warped, int border, RNG& rng) const;
\r
606 void generateRandomTransform(Point2f srcCenter, Point2f dstCenter,
\r
607 Mat& transform, RNG& rng, bool inverse=false) const;
\r
608 double backgroundMin, backgroundMax;
\r
611 double lambdaMin, lambdaMax;
\r
612 double thetaMin, thetaMax;
\r
613 double phiMin, phiMax;
\r
617 class CV_EXPORTS LDetector
\r
621 LDetector(int _radius, int _threshold, int _nOctaves,
\r
622 int _nViews, double _baseFeatureSize, double _clusteringDistance);
\r
623 void operator()(const Mat& image, Vector<KeyPoint>& keypoints, int maxCount=0, bool scaleCoords=true) const;
\r
624 void operator()(const Vector<Mat>& pyr, Vector<KeyPoint>& keypoints, int maxCount=0, bool scaleCoords=true) const;
\r
625 void getMostStable2D(const Mat& image, Vector<KeyPoint>& keypoints,
\r
626 int maxCount, const PatchGenerator& patchGenerator) const;
\r
627 void setVerbose(bool verbose);
\r
629 void read(const FileNode& node);
\r
630 void write(FileStorage& fs, const String& name=String()) const;
\r
638 double baseFeatureSize;
\r
639 double clusteringDistance;
\r
643 class CV_EXPORTS FernClassifier
\r
647 FernClassifier(const FileNode& node);
\r
648 FernClassifier(const Vector<Point2f>& points,
\r
649 const Vector<Ptr<Mat> >& refimgs,
\r
650 const Vector<int>& labels=Vector<int>(),
\r
651 int _nclasses=0, int _patchSize=PATCH_SIZE,
\r
652 int _signatureSize=DEFAULT_SIGNATURE_SIZE,
\r
653 int _nstructs=DEFAULT_STRUCTS,
\r
654 int _structSize=DEFAULT_STRUCT_SIZE,
\r
655 int _nviews=DEFAULT_VIEWS,
\r
656 int _compressionMethod=COMPRESSION_NONE,
\r
657 const PatchGenerator& patchGenerator=PatchGenerator());
\r
658 virtual ~FernClassifier();
\r
659 virtual void read(const FileNode& n);
\r
660 virtual void write(FileStorage& fs, const String& name=String()) const;
\r
661 virtual void trainFromSingleView(const Mat& image,
\r
662 const Vector<KeyPoint>& keypoints,
\r
663 int _patchSize=PATCH_SIZE,
\r
664 int _signatureSize=DEFAULT_SIGNATURE_SIZE,
\r
665 int _nstructs=DEFAULT_STRUCTS,
\r
666 int _structSize=DEFAULT_STRUCT_SIZE,
\r
667 int _nviews=DEFAULT_VIEWS,
\r
668 int _compressionMethod=COMPRESSION_NONE,
\r
669 const PatchGenerator& patchGenerator=PatchGenerator());
\r
670 virtual void train(const Vector<Point2f>& points,
\r
671 const Vector<Ptr<Mat> >& refimgs,
\r
672 const Vector<int>& labels=Vector<int>(),
\r
673 int _nclasses=0, int _patchSize=PATCH_SIZE,
\r
674 int _signatureSize=DEFAULT_SIGNATURE_SIZE,
\r
675 int _nstructs=DEFAULT_STRUCTS,
\r
676 int _structSize=DEFAULT_STRUCT_SIZE,
\r
677 int _nviews=DEFAULT_VIEWS,
\r
678 int _compressionMethod=COMPRESSION_NONE,
\r
679 const PatchGenerator& patchGenerator=PatchGenerator());
\r
680 virtual int operator()(const Mat& img, Point2f kpt, Vector<float>& signature) const;
\r
681 virtual int operator()(const Mat& patch, Vector<float>& signature) const;
\r
682 virtual void clear();
\r
683 void setVerbose(bool verbose);
\r
685 int getClassCount() const;
\r
686 int getStructCount() const;
\r
687 int getStructSize() const;
\r
688 int getSignatureSize() const;
\r
689 int getCompressionMethod() const;
\r
690 Size getPatchSize() const;
\r
694 uchar x1, y1, x2, y2;
\r
695 Feature() : x1(0), y1(0), x2(0), y2(0) {}
\r
696 Feature(int _x1, int _y1, int _x2, int _y2)
\r
697 : x1((uchar)_x1), y1((uchar)_y1), x2((uchar)_x2), y2((uchar)_y2)
\r
699 template<typename _Tp> bool operator ()(const Mat_<_Tp>& patch) const
\r
700 { return patch(y1,x1) > patch(y2, x2); }
\r
706 DEFAULT_STRUCTS = 50,
\r
707 DEFAULT_STRUCT_SIZE = 9,
\r
708 DEFAULT_VIEWS = 5000,
\r
709 DEFAULT_SIGNATURE_SIZE = 176,
\r
710 COMPRESSION_NONE = 0,
\r
711 COMPRESSION_RANDOM_PROJ = 1,
\r
712 COMPRESSION_PCA = 2,
\r
713 DEFAULT_COMPRESSION_METHOD = COMPRESSION_NONE
\r
717 virtual void prepare(int _nclasses, int _patchSize, int _signatureSize,
\r
718 int _nstructs, int _structSize,
\r
719 int _nviews, int _compressionMethod);
\r
720 virtual void finalize(RNG& rng);
\r
721 virtual int getLeaf(int fidx, const Mat& patch) const;
\r
728 int compressionMethod;
\r
729 int leavesPerStruct;
\r
731 Vector<Feature> features;
\r
732 Vector<int> classCounters;
\r
733 Vector<float> posteriors;
\r
736 class CV_EXPORTS PlanarObjectDetector
\r
739 PlanarObjectDetector();
\r
740 PlanarObjectDetector(const FileNode& node);
\r
741 PlanarObjectDetector(const Vector<Mat>& pyr, int _npoints=300,
\r
742 int _patchSize=FernClassifier::PATCH_SIZE,
\r
743 int _nstructs=FernClassifier::DEFAULT_STRUCTS,
\r
744 int _structSize=FernClassifier::DEFAULT_STRUCT_SIZE,
\r
745 int _nviews=FernClassifier::DEFAULT_VIEWS,
\r
746 const LDetector& detector=LDetector(),
\r
747 const PatchGenerator& patchGenerator=PatchGenerator());
\r
748 virtual ~PlanarObjectDetector();
\r
749 virtual void train(const Vector<Mat>& pyr, int _npoints=300,
\r
750 int _patchSize=FernClassifier::PATCH_SIZE,
\r
751 int _nstructs=FernClassifier::DEFAULT_STRUCTS,
\r
752 int _structSize=FernClassifier::DEFAULT_STRUCT_SIZE,
\r
753 int _nviews=FernClassifier::DEFAULT_VIEWS,
\r
754 const LDetector& detector=LDetector(),
\r
755 const PatchGenerator& patchGenerator=PatchGenerator());
\r
756 virtual void train(const Vector<Mat>& pyr, const Vector<KeyPoint>& keypoints,
\r
757 int _patchSize=FernClassifier::PATCH_SIZE,
\r
758 int _nstructs=FernClassifier::DEFAULT_STRUCTS,
\r
759 int _structSize=FernClassifier::DEFAULT_STRUCT_SIZE,
\r
760 int _nviews=FernClassifier::DEFAULT_VIEWS,
\r
761 const LDetector& detector=LDetector(),
\r
762 const PatchGenerator& patchGenerator=PatchGenerator());
\r
763 Rect getModelROI() const;
\r
764 Vector<KeyPoint> getModelPoints() const;
\r
765 const LDetector& getDetector() const;
\r
766 const FernClassifier& getClassifier() const;
\r
767 void setVerbose(bool verbose);
\r
769 void read(const FileNode& node);
\r
770 void write(FileStorage& fs, const String& name=String()) const;
\r
771 bool operator()(const Mat& image, Mat& H, Vector<Point2f>& corners) const;
\r
772 bool operator()(const Vector<Mat>& pyr, const Vector<KeyPoint>& keypoints,
\r
773 Mat& H, Vector<Point2f>& corners, Vector<int>* pairs=0) const;
\r
778 Vector<KeyPoint> modelPoints;
\r
779 LDetector ldetector;
\r
780 FernClassifier fernClassifier;
\r
785 #endif /* __cplusplus */
\r
787 #endif /* __CVAUX_HPP__ */
\r