forked from benpryke/BPTLD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tracker.h
113 lines (88 loc) · 3.93 KB
/
Tracker.h
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
/* Copyright 2011 Ben Pryke.
This file is part of Ben Pryke's TLD Implementation available under the
terms of the GNU General Public License as published by the Free Software
Foundation. This software is provided without warranty of ANY kind. */
#pragma once
#include "cv.h"
#include "highgui.h"
#include "IntegralImage.h"
#include "Classifier.h"
#include <math.h>
using namespace cv;
// Constants -----------------------------------------------------------------
// The number of points in a single dimension on the bounding-box
#define DIM_POINTS 10
// Total number of points on the bounding-box
#define TOTAL_POINTS (DIM_POINTS * DIM_POINTS)
// Defines the size of the search window in cvCalcOpticalFlowPyrLK
#define WINDOW_SIZE 4
// Maximal pyramid level number
// If 0, pyramids are not used (single level); if 1, two levels are used etc.
#define LEVEL 5
/* The Median Flow Tracker.
Algorithm:
1) Initialise uniformly distributed set of points over the previous
frame's trajectory patch
2) Track these points using the Lucas-Kanade algorithm
3) Estimate the tracking error of each point
4) Filter out the tracked points with greatest error (typically 50% of
points)
5) Set the bounding-box scale and position for the current frame based on
the median scale and position changes of the remaining points
This implementation does not implement steps 3 and 4. */
class Tracker {
// Private ===============================================================
private:
// Size of each frame
int width;
int height;
// Previous video stream frame
IplImage *prevFrame;
// Buffers for the pyramids used by cvCalcOpticalFlowPyrLK
IplImage *prevPyramid;
IplImage *nextPyramid;
// The coordinates of the points placed in the bounding-box
// These points are those that are tracked
// predPoints = predicted 1st frame points from tracking backwards
CvPoint2D32f *prevPoints;
CvPoint2D32f *nextPoints;
//CvPoint2D32f *predPoints;
// Size of the search window of each pyramid level in cvCalcOpticalFlowPyrLK
CvSize *windowSize;
// Status output array of cvCalcOpticalFlowPyrLK. Elements are set to 1 if
// the flow for the corresponding feature has been found, otherwise 0
// status is for forward tracking, predStatus is for backward tracking
char *status;
//char *predStatus;
// Specifies the termination criteria of the iterative search algorithm in
// cvCalcOpticalFlowPyrLK
TermCriteria *termCriteria;
// Pointer to the classifier for the entire program
Classifier *classifier;
/* Returns the median of an array of float values.
Note: has side-effect of sorting array A.
A: the array
length: length of array A */
float median(float *A, int length);
// Public ================================================================
public:
/* Constructor. Initialises the tracker.
frameWidth: width of the video stream frames
frameHeight: height of the video stream frames
frameSize: size of the video frame as a CvSize object
firstFrame: the first video stream frame
classifier: pointer to the classifier for the program */
Tracker(int frameWidth, int frameHeight, CvSize *frameSize, IplImage *firstFrame, Classifier *classifier);
/* Tracks the region of the input frame indicated by the given
bounding-box.
Returns the estimated new bounding box
[x, y, width, height, confidence].
nextFrame: next video stream frame
bb: array containing the trajectory bounding-box
[x, y, width, height] */
double *track(IplImage *nextFrameIpl, IntegralImage *nextFrame, double *bb);
/* Setter for prevFrame (also frees the current value of prevFrame). */
void setPrevFrame(IplImage *frame);
/* Destructor. */
~Tracker();
};