forked from kshitijagrwl/kalman-camshift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.hpp
175 lines (140 loc) · 5.08 KB
/
tracker.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* Copyright (C) 2016 kshitij Agrawal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#ifndef __TRACKER_H__
#define __TRACKER_H__
#include "cv.h"
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utility.hpp>
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/features2d.hpp>
using namespace std;
using namespace cv;
///<summary>A color tracker using OpenCV camshift and an update scheme to
///track a patch in the input image. The supplied parameters vMin, vMax,
///and sMin control the behavior of the color matching while the parameters
///of sBox and the histogram update control how new color data are integrated
///into the currently tracked histogram.</summary>
class Tracker {
public:
///<summary>Initialization parameters.</summary>
struct InitParams {
///<summary>Set default parameter values.</summary>
InitParams();
int histDims;
int vMin;
int vMax;
int sMin;
int sBox;
bool showBackproject;
bool showControlsGUI;
bool showHistogram;
float histRanges[2];
};
static int g_selId;
static bool g_selectObject;
static int g_initTracking;
static cv::Point g_selOrigin;
static cv::Rect g_selRect;
Tracker();
~Tracker();
void Init(const cv::Size &frameSize, const InitParams &initParams);
// void Deinit();
void InitTrackWindow(const cv::Mat &img, const cv::Rect &selRect);
void ProcessFrame(const cv::Mat &img,cv::Mat &out);
// void SetSubdivBoxSize(int boxSize);
// void ShowBackproject();
// void HideBackproject();
void ShowControlsGUI();
void HideControlsGUI();
// void ShowHistogram();
// void HideHistogram();
bool ToggleShowBackproject();
// bool ToggleShowHistogram();
bool IsTracking() const;
void StopTracking();
const cv::Rect &TrackWindow() const;
const cv::RotatedRect &TrackBox() const;
const CvHistogram &TrackHistogram() const;
int TrackHistogramDims() const;
const cv::Mat Hue() const;
const cv::Mat BackProjection() const;
const std::string &Name() const;
///<summary>Get the velocity.</summary>
///<remarks><para>Normalizes velocity by the size of the image so that the
///implementation is safe from changes in image size. Recommended to use an
///aging mechanism on this value since it is very noisy. Something like
///velocity = (v_prev * .75) + (v_now * 0.25) should be
///okay.</para></remarks>
// cv::Scalar ComputeNormalizedVelocity() const;
private:
// bool ComputeCamshift(const IplImage* hue, const IplImage* mask);
// void AdaptHistogram(IplImage* hue, IplImage* mask, IplImage* out);
// void SubdivideSumTrackWnd(int sBox,
// int* numRows, int* numCols,
// std::vector<float>* subdivs);
// void PresentOutput(IplImage *img);
static void OnMouse(int event, int x, int y, int flags, void *param);
void PredictPos();
void DrawStuff(cv::Mat &out);
cv::KalmanFilter m_KF;
cv::Mat m_state;
cv::Mat m_measured;
cv::Mat m_estimated;
vector<Point> m_past, m_kalmanv;
int m_id;
cv::Size m_frameSize;
Mat m_imgHue, m_imgMask, m_imgHSV, m_hist;
Mat m_frame, m_imgBackproject;
// Mat objmask;
// CvHistogram* m_histTrackWnd;
int m_histDims, m_hSize;
int m_binWidth;
float m_histRanges[2];
Mat m_histImg;
///<summary>Controls the amount of the new track window histogram to weight
///into the current tracking histogram.</summary>
int m_ageRatio;
bool m_showBackproject;
bool m_showControlsGUI;
bool m_showHistogram;
std::string m_controlsGUIWndName;
std::string m_backprojectWndName;
std::string m_histogramWndName;
int m_tracking;
bool m_initialized;
cv::Rect m_trackWindow;
cv::RotatedRect m_trackBox;
cv::Rect m_trackCompRect;
cv::Point m_trackPosTwoFramesBack;
float m_trackAreaTwoFramesBack;
cv::Scalar m_velocity;
bool m_reaquire;
// Camshift parameters.
int m_vMin;
int m_vMax;
int m_sMin;
int m_sBox;
};
#endif //ADAPTIVE_HISTOGRAM_CAMSHIFT