@@ -29,46 +29,42 @@ class PersonTrackers {
29
29
PersonTrackers () : trackIdGenerator{0 }, similarityThreshold{0 .7f }, maxDisappeared{10 } {}
30
30
31
31
void similarity (std::list<TrackableObject> &tos) {
32
- if (trackables.size () > 0 ) {
33
- for (const auto & to : tos) {
34
- std::deque<std::pair<int , float >> sim;
35
- for (auto &tracker : trackables) {
36
- if (!tracker.second .updated ) {
37
- float cosine = cosineSimilarity (to.reid , tracker.second .reid );
38
- if (cosine > similarityThreshold) {
39
- sim.push_back (std::make_pair (tracker.first , cosine));
40
- }
32
+ for (const auto & to : tos) {
33
+ std::deque<std::pair<int , float >> sim;
34
+ for (auto &tracker : trackables) {
35
+ if (!tracker.second .updated ) {
36
+ float cosine = cosineSimilarity (to.reid , tracker.second .reid );
37
+ if (cosine > similarityThreshold) {
38
+ sim.push_back (std::make_pair (tracker.first , cosine));
41
39
}
42
40
}
41
+ }
43
42
44
- if (sim.empty ()) {
45
- trackables.insert ({ trackIdGenerator, to });
46
- trackables.at (trackIdGenerator).updated = true ;
47
- trackables.at (trackIdGenerator).disappeared = 0 ;
48
- trackIdGenerator += 1 ;
49
- } else {
50
- int maxSimilarity = std::max_element (sim.begin (), sim.end (), [](std::pair<int , float > a, std::pair<int , float > b) {
51
- return std::get<1 >(a) > std::get<1 >(b);
52
- })->first ;
53
- trackables.at (maxSimilarity) = to;
54
- trackables.at (maxSimilarity).updated = true ;
55
- trackables.at (maxSimilarity).disappeared = 0 ;
56
- }
43
+ if (sim.empty ()) {
44
+ trackables.insert ({ trackIdGenerator, to });
45
+ trackables.at (trackIdGenerator).updated = true ;
46
+ trackables.at (trackIdGenerator).disappeared = 0 ;
47
+ trackIdGenerator += 1 ;
48
+ } else {
49
+ int maxSimilarity = std::max_element (sim.begin (), sim.end (), [](std::pair<int , float > a, std::pair<int , float > b) {
50
+ return std::get<1 >(a) > std::get<1 >(b);
51
+ })->first ;
52
+ trackables.at (maxSimilarity) = to;
53
+ trackables.at (maxSimilarity).updated = true ;
54
+ trackables.at (maxSimilarity).disappeared = 0 ;
57
55
}
56
+ }
58
57
59
- for (auto it = trackables.begin (); it != trackables.end (); ) {
60
- if (!it->second .updated ) {
61
- it->second .disappeared += 1 ;
62
- if (it->second .disappeared > maxDisappeared) {
63
- it = trackables.erase (it);
64
- continue ;
65
- }
58
+ for (auto it = trackables.begin (); it != trackables.end (); ) {
59
+ if (!it->second .updated ) {
60
+ it->second .disappeared += 1 ;
61
+ if (it->second .disappeared > maxDisappeared) {
62
+ it = trackables.erase (it);
63
+ continue ;
66
64
}
67
- it->second .updated = false ;
68
- ++it;
69
65
}
70
- } else {
71
- registerTrackables (tos) ;
66
+ it-> second . updated = false ;
67
+ ++it ;
72
68
}
73
69
}
74
70
@@ -86,14 +82,6 @@ class PersonTrackers {
86
82
return static_cast <float >(dot / (sqrt (denomA) * sqrt (denomB) + 1e-6 ));
87
83
}
88
84
89
- void registerTrackables (std::list<TrackableObject> &tos) {
90
- for (auto &to : tos) {
91
- to.disappeared = 0 ;
92
- trackables.insert ({trackIdGenerator, to});
93
- trackIdGenerator += 1 ;
94
- }
95
- }
96
-
97
85
public:
98
86
std::unordered_map<int , TrackableObject> trackables;
99
87
0 commit comments