hybridtracker.hpp
Go to the documentation of this file.
1 //*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
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.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
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.
26 //
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.
29 //
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.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_HYBRIDTRACKER_H_
44 #define __OPENCV_HYBRIDTRACKER_H_
45 
46 #include "opencv2/core/core.hpp"
51 #include "opencv2/ml/ml.hpp"
52 
53 #ifdef __cplusplus
54 
55 namespace cv
56 {
57 
58 // Motion model for tracking algorithm. Currently supports objects that do not move much.
59 // To add Kalman filter
60 struct CV_EXPORTS CvMotionModel
61 {
62  enum {LOW_PASS_FILTER = 0, KALMAN_FILTER = 1, EM = 2};
63 
65  {
66  }
67 
68  float low_pass_gain; // low pass gain
69 };
70 
71 // Mean Shift Tracker parameters for specifying use of HSV channel and CamShift parameters.
72 struct CV_EXPORTS CvMeanShiftTrackerParams
73 {
74  enum { H = 0, HS = 1, HSV = 2 };
76  CvTermCriteria term_crit = CvTermCriteria());
77 
79  vector<float> h_range;
80  vector<float> s_range;
81  vector<float> v_range;
83 };
84 
85 // Feature tracking parameters
86 struct CV_EXPORTS CvFeatureTrackerParams
87 {
88  enum { SIFT = 0, SURF = 1, OPTICAL_FLOW = 2 };
89  CvFeatureTrackerParams(int featureType = 0, int windowSize = 0)
90  {
91  feature_type = featureType;
92  window_size = windowSize;
93  }
94 
95  int feature_type; // Feature type to use
96  int window_size; // Window size in pixels around which to search for new window
97 };
98 
99 // Hybrid Tracking parameters for specifying weights of individual trackers and motion model.
100 struct CV_EXPORTS CvHybridTrackerParams
101 {
102  CvHybridTrackerParams(float ft_tracker_weight = 0.5, float ms_tracker_weight = 0.5,
105  CvMotionModel model = CvMotionModel());
106 
113 };
114 
115 // Performs Camshift using parameters from MeanShiftTrackerParams
116 class CV_EXPORTS CvMeanShiftTracker
117 {
118 private:
119  Mat hsv, hue;
120  Mat backproj;
121  Mat mask, maskroi;
122  MatND hist;
123  Rect prev_trackwindow;
124  RotatedRect prev_trackbox;
125  Point2f prev_center;
126 
127 public:
129 
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();
140 };
141 
142 // Performs SIFT/SURF feature tracking using parameters from FeatureTrackerParams
143 class CV_EXPORTS CvFeatureTracker
144 {
145 private:
146  Ptr<Feature2D> dd;
147  Ptr<DescriptorMatcher> matcher;
148  vector<DMatch> matches;
149 
150  Mat prev_image;
151  Mat prev_image_bw;
152  Rect prev_trackwindow;
153  Point2d prev_center;
154 
155  int ittr;
156  vector<Point2f> features[2];
157 
158 public:
161 
164  ~CvFeatureTracker();
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();
172 };
173 
174 // Performs Hybrid Tracking and combines individual trackers using EM or filters
175 class CV_EXPORTS CvHybridTracker
176 {
177 private:
178  CvMeanShiftTracker* mstracker;
179  CvFeatureTracker* fttracker;
180 
181  CvMat* samples;
182  CvMat* labels;
183 
184  Rect prev_window;
185  Point2f prev_center;
186  Mat prev_proj;
187  RotatedRect trackbox;
188 
189  int ittr;
190  Point2f curr_center;
191 
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);
197 
198 public:
200  CvHybridTracker();
202  ~CvHybridTracker();
203 
204  void newTracker(Mat image, Rect selection);
205  void updateTracker(Mat image);
206  Rect getTrackingWindow();
207 };
208 
216 }
217 
218 #endif
219 
220 #endif
struct CvTermCriteria CvTermCriteria
CvTermCriteria term_crit
Definition: hybridtracker.hpp:82
CvPoint2D32f p2
Definition: legacy.hpp:578
Definition: ml.hpp:562
int motion_model
Definition: hybridtracker.hpp:111
Definition: hybridtracker.hpp:175
CvFeatureTrackerParams FeatureTrackerParams
Definition: hybridtracker.hpp:211
CvMotionModel MotionModel
Definition: hybridtracker.hpp:209
CvPoint center
Definition: core_c.h:1290
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: highgui_c.h:230
float ft_tracker_weight
Definition: hybridtracker.hpp:107
CvMeanShiftTrackerParams params
Definition: hybridtracker.hpp:128
vector< float > s_range
Definition: hybridtracker.hpp:80
CvHybridTrackerParams HybridTrackerParams
Definition: hybridtracker.hpp:212
CvMeanShiftTrackerParams MeanShiftTrackerParams
Definition: hybridtracker.hpp:210
CvFeatureTrackerParams params
Definition: hybridtracker.hpp:160
int feature_type
Definition: hybridtracker.hpp:95
vector< float > v_range
Definition: hybridtracker.hpp:81
SIFT implementation.
Definition: features2d.hpp:58
int tracking_type
Definition: hybridtracker.hpp:78
int CvHistogram * hist
Definition: imgproc_c.h:440
float low_pass_gain
Definition: hybridtracker.hpp:68
SURF implementation.
Definition: features2d.hpp:107
int window_size
Definition: hybridtracker.hpp:96
Definition: hybridtracker.hpp:143
The Image Processing.
CvHybridTrackerParams params
Definition: hybridtracker.hpp:199
Definition: hybridtracker.hpp:60
Definition: types_c.h:645
Definition: hybridtracker.hpp:74
The Core Functionality.
Definition: hybridtracker.hpp:72
The n-dimensional matrix class.
Definition: core.hpp:1688
CvFeatureTracker FeatureTracker
Definition: hybridtracker.hpp:214
CvHybridTracker HybridTracker
Definition: hybridtracker.hpp:215
Definition: types_c.h:997
OutputArray OutputArray labels
Definition: imgproc.hpp:823
GLuint GLuint GLsizei GLenum type
Definition: core_c.h:114
GLenum const GLfloat * params
Definition: compat.hpp:688
The rotated 2D rectangle.
Definition: core.hpp:913
Mat disp_matches
Definition: hybridtracker.hpp:159
vector< float > h_range
Definition: hybridtracker.hpp:79
CvMeanShiftTracker MeanShiftTracker
Definition: hybridtracker.hpp:213
CvMotionModel()
Definition: hybridtracker.hpp:64
The Object and Feature Tracking.
float low_pass_gain
Definition: hybridtracker.hpp:112
Definition: hybridtracker.hpp:116
CvMeanShiftTrackerParams ms_params
Definition: hybridtracker.hpp:110
CvFeatureTrackerParams ft_params
Definition: hybridtracker.hpp:109
Definition: hybridtracker.hpp:100
Smart pointer to dynamically allocated objects.
Definition: core.hpp:1268
const Cv3dTrackerCameraIntrinsics CvSize float IplImage * samples[]
Definition: legacy.hpp:936
CvArr const CvArr * mask
Definition: core_c.h:288
CvFeatureTrackerParams(int featureType=0, int windowSize=0)
Definition: hybridtracker.hpp:89
float ms_tracker_weight
Definition: hybridtracker.hpp:108
Definition: hybridtracker.hpp:86