-
Notifications
You must be signed in to change notification settings - Fork 18
/
Tracker.h
71 lines (55 loc) · 2.42 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
#ifndef TRACKER_H
#define TRACKER_H
#include "FaceDetector.h"
#include "TrackItem.h"
#include <map>
namespace cvip
{
/**
* Tracker class written according to a "kind of" decorator pattern:
* Take a detector and wrap it with this Tracker
*
* @todo convert FaceDetector* to Detector* after Detectors are abstracted
* @todo include "Detector.h" rather than "FaceDetector.h" after abstraction
* @todo update totalTime()
* @author evangelos sariyanidi / sariyanidi[at]gmail[dot]com
* @date april 2011
*/
class Tracker
{
public:
// construct tracker using a detector
Tracker( cvip::FaceDetector* _detector ) : detector(_detector), tStart(cv::getTickCount()), numFrames(0) {}
// in destructor delete detector and all track items
~Tracker();
// Track items on video
void onVideo();
// add/drop trackItems
void add(cvip::TrackItem* ti) { trackItems.insert(std::pair<uint, TrackItem*>(ti->id, ti)); }
void drop(uint id) { delete trackItems[id]; trackItems.erase(id); }
// update trackItems with fresh detections
void updateWith(std::vector<DetectionRect>& freshDetects);
// record regarding tracker
uint numItems() const { return trackItems.size(); }
double totalTime() const { return (double)(cv::getTickCount()-tStart);/*/CLOCKS_PER_SEC*/; }
//! @property allowed num of inactive frames, drop tracking if this number exceeded
static const unsigned short NUM_MAX_INACTIVE_FRAMES = 20;
//! @property minimum number of detections before start to track an item
static const unsigned short NUM_MIN_DETECTIONS = 3;
private:
//! @property detector to detect objects
cvip::FaceDetector* detector;
//! @property items being tracked -> associate each item with its id
std::map<uint, cvip::TrackItem*> trackItems;
//! @property tick count of Tracker initialization time
unsigned long tStart;
//! @property total number of frames run
unsigned long numFrames;
// see definition of Tracker::updateItems() for comments of these:
std::map<uint, bool>
updateActiveItems(std::vector<DetectionRect>& freshDetects);
void updateInactiveItems(const std::map<uint, bool>& flagUpdated);
void addNewItems(std::vector<DetectionRect>& freshDetects);
};
}
#endif // TRACKER_H