-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathObjectCounter.cpp
More file actions
81 lines (67 loc) · 2.06 KB
/
Copy pathObjectCounter.cpp
File metadata and controls
81 lines (67 loc) · 2.06 KB
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
#include "ObjectCounter.hpp"
#include "Utils.hpp"
ObjectCounter::ObjectCounter(cv::Rect referenceBox) {
Config configuration;
memset(this->countedPoint, -1, sizeof(this->countedPoint));
this->pos = 0;
this->totalLeftCount = configuration.GetLeftCounter();
this->totalRightCount = configuration.GetRightCounter();
this->referenceBox = referenceBox;
}
bool ObjectCounter::AccountPoint(TrackedObject point) {
bool newElement = true;
bool addedNew = false;
for (auto it : this->countedPoint) {
if (it == point.id) {
newElement = false;
break;
}
}
// printf("id: %d, Width: %d, Traj: %f\n",
// point.id, point.rect.width, fabs(point.pt.x - point.pt0.x) );
if (newElement &&
point.framesAlive > 2 &&
abs(point.pt.x - point.pt0.x) > (1.0 * this->referenceBox.width) &&
point.rect.width > (0.65 * this->referenceBox.width) &&
point.rect.width < (1.50 * this->referenceBox.width)) {
if (point.pt.x > this->referenceBox.tl().x &&
point.pt.x < this->referenceBox.br().x &&
point.pt.y > this->referenceBox.tl().y &&
point.pt.y < this->referenceBox.br().y) {
Config configuration;
if (point.ltr) {
this->totalLeftCount++;
configuration.SetLeftCounter(this->totalLeftCount);
}
else {
this->totalRightCount++;
configuration.SetRightCounter(this->totalRightCount);
}
this->countedPoint[pos++] = point.id;
if (pos >= sizeof(countedPoint)/sizeof(countedPoint[0])) {
pos = 0;
}
addedNew = true;
}
}
return addedNew;
}
unsigned int ObjectCounter::GetTotalPoints() {
return this->totalLeftCount + this->totalRightCount;
}
unsigned int ObjectCounter::GetLTRPoints() {
return this->totalLeftCount;
}
unsigned int ObjectCounter::GetRTLPoints() {
return this->totalRightCount;
}
void ObjectCounter::ZeroCounters() {
Config configuration;
this->totalLeftCount = 0;
this->totalRightCount = 0;
configuration.SetLeftCounter(this->totalLeftCount);
configuration.SetLeftCounter(this->totalRightCount);
}
void ObjectCounter::SetReferenceBox(cv::Rect referenceBox) {
this->referenceBox = referenceBox;
}