1 //*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of Intel Corporation may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #ifndef __OPENCV_HYBRIDTRACKER_H_
44 #define __OPENCV_HYBRIDTRACKER_H_
46 #include "opencv2/core/core.hpp"
47 #include "opencv2/core/operations.hpp"
48 #include "opencv2/imgproc/imgproc.hpp"
49 #include "opencv2/features2d/features2d.hpp"
50 #include "opencv2/video/tracking.hpp"
51 #include "opencv2/ml/ml.hpp"
58 // Motion model for tracking algorithm. Currently supports objects that do not move much.
59 // To add Kalman filter
60 struct CV_EXPORTS CvMotionModel
62 enum {LOW_PASS_FILTER = 0, KALMAN_FILTER = 1, EM = 2};
68 float low_pass_gain; // low pass gain
71 // Mean Shift Tracker parameters for specifying use of HSV channel and CamShift parameters.
72 struct CV_EXPORTS CvMeanShiftTrackerParams
74 enum { H = 0, HS = 1, HSV = 2 };
75 CvMeanShiftTrackerParams(int tracking_type = CvMeanShiftTrackerParams::HS,
76 CvTermCriteria term_crit = CvTermCriteria());
79 vector<float> h_range;
80 vector<float> s_range;
81 vector<float> v_range;
82 CvTermCriteria term_crit;
85 // Feature tracking parameters
86 struct CV_EXPORTS CvFeatureTrackerParams
88 enum { SIFT = 0, SURF = 1, OPTICAL_FLOW = 2 };
89 CvFeatureTrackerParams(int featureType = 0, int windowSize = 0)
95 int feature_type; // Feature type to use
96 int window_size; // Window size in pixels around which to search for new window
99 // Hybrid Tracking parameters for specifying weights of individual trackers and motion model.
100 struct CV_EXPORTS CvHybridTrackerParams
102 CvHybridTrackerParams(float ft_tracker_weight = 0.5, float ms_tracker_weight = 0.5,
103 CvFeatureTrackerParams ft_params = CvFeatureTrackerParams(),
104 CvMeanShiftTrackerParams ms_params = CvMeanShiftTrackerParams(),
105 CvMotionModel model = CvMotionModel());
107 float ft_tracker_weight;
108 float ms_tracker_weight;
109 CvFeatureTrackerParams ft_params;
110 CvMeanShiftTrackerParams ms_params;
115 // Performs Camshift using parameters from MeanShiftTrackerParams
116 class CV_EXPORTS CvMeanShiftTracker
123 Rect prev_trackwindow;
124 RotatedRect prev_trackbox;
128 CvMeanShiftTrackerParams params;
130 CvMeanShiftTracker();
131 explicit CvMeanShiftTracker(CvMeanShiftTrackerParams _params);
132 ~CvMeanShiftTracker();
133 void newTrackingWindow(Mat image, Rect selection);
134 RotatedRect updateTrackingWindow(Mat image);
135 Mat getHistogramProjection(int type);
136 void setTrackingWindow(Rect _window);
137 Rect getTrackingWindow();
138 RotatedRect getTrackingEllipse();
139 Point2f getTrackingCenter();
142 // Performs SIFT/SURF feature tracking using parameters from FeatureTrackerParams
143 class CV_EXPORTS CvFeatureTracker
147 Ptr<DescriptorMatcher> matcher;
148 vector<DMatch> matches;
152 Rect prev_trackwindow;
156 vector<Point2f> features[2];
160 CvFeatureTrackerParams params;
163 explicit CvFeatureTracker(CvFeatureTrackerParams params);
165 void newTrackingWindow(Mat image, Rect selection);
166 Rect updateTrackingWindow(Mat image);
167 Rect updateTrackingWindowWithSIFT(Mat image);
168 Rect updateTrackingWindowWithFlow(Mat image);
169 void setTrackingWindow(Rect _window);
170 Rect getTrackingWindow();
171 Point2f getTrackingCenter();
174 // Performs Hybrid Tracking and combines individual trackers using EM or filters
175 class CV_EXPORTS CvHybridTracker
178 CvMeanShiftTracker* mstracker;
179 CvFeatureTracker* fttracker;
187 RotatedRect trackbox;
192 inline float getL2Norm(Point2f p1, Point2f p2);
193 Mat getDistanceProjection(Mat image, Point2f center);
194 Mat getGaussianProjection(Mat image, int ksize, double sigma, Point2f center);
195 void updateTrackerWithEM(Mat image);
196 void updateTrackerWithLowPassFilter(Mat image);
199 CvHybridTrackerParams params;
201 explicit CvHybridTracker(CvHybridTrackerParams params);
204 void newTracker(Mat image, Rect selection);
205 void updateTracker(Mat image);
206 Rect getTrackingWindow();
209 typedef CvMotionModel MotionModel;
210 typedef CvMeanShiftTrackerParams MeanShiftTrackerParams;
211 typedef CvFeatureTrackerParams FeatureTrackerParams;
212 typedef CvHybridTrackerParams HybridTrackerParams;
213 typedef CvMeanShiftTracker MeanShiftTracker;
214 typedef CvFeatureTracker FeatureTracker;
215 typedef CvHybridTracker HybridTracker;