OpenShot Library | libopenshot  0.2.7
sort.hpp
Go to the documentation of this file.
1 
2 #include "KalmanTracker.h"
3 #include "Hungarian.h"
4 
5 #include <iostream>
6 #include <fstream>
7 #include <iomanip> // to format image names using setw() and setfill()
8 #include <set>
9 
10 #include "opencv2/video/tracking.hpp"
11 #include "opencv2/highgui/highgui.hpp"
12 
13 #ifndef _OPENCV_KCFTRACKER_HPP_
14 #define _OPENCV_KCFTRACKER_HPP_
15 #endif
16 #pragma once
17 
18 typedef struct TrackingBox
19 {
20  int frame = 0;
21  float confidence = 0;
22  int classId = 0;
23  int id = 0;
24  cv::Rect_<float> box = cv::Rect_<float>(0.0, 0.0, 0.0, 0.0);
26  TrackingBox(int _frame, float _confidence, int _classId, int _id) : frame(_frame), confidence(_confidence), classId(_classId), id(_id) {}
27 } TrackingBox;
28 
30 {
31 public:
32  // Constructor
33  SortTracker(int max_age = 7, int min_hits = 2);
34  // Initialize tracker
35 
36  // Update position based on the new frame
37  void update(std::vector<cv::Rect> detection, int frame_count, double image_diagonal, std::vector<float> confidences, std::vector<int> classIds);
38  double GetIOU(cv::Rect_<float> bb_test, cv::Rect_<float> bb_gt);
39  double GetCentroidsDistance(cv::Rect_<float> bb_test, cv::Rect_<float> bb_gt);
40  std::vector<KalmanTracker> trackers;
41 
42  double max_centroid_dist_norm = 0.05;
43 
44  std::vector<cv::Rect_<float>> predictedBoxes;
45  std::vector<std::vector<double>> centroid_dist_matrix;
46  std::vector<int> assignment;
47  std::set<int> unmatchedDetections;
48  std::set<int> unmatchedTrajectories;
49  std::set<int> allItems;
50  std::set<int> matchedItems;
51  std::vector<cv::Point> matchedPairs;
52 
53  std::vector<TrackingBox> frameTrackingResult;
54  std::vector<int> dead_trackers_id;
55 
56  unsigned int trkNum = 0;
57  unsigned int detNum = 0;
58  int _min_hits;
59  int _max_age;
61 };
std::vector< cv::Rect_< float > > predictedBoxes
Definition: sort.hpp:44
std::vector< int > dead_trackers_id
Definition: sort.hpp:54
std::vector< int > assignment
Definition: sort.hpp:46
bool alive_tracker
Definition: sort.hpp:60
std::vector< cv::Point > matchedPairs
Definition: sort.hpp:51
TrackingBox(int _frame, float _confidence, int _classId, int _id)
Definition: sort.hpp:26
std::set< int > unmatchedTrajectories
Definition: sort.hpp:48
std::set< int > unmatchedDetections
Definition: sort.hpp:47
int classId
Definition: sort.hpp:22
std::vector< KalmanTracker > trackers
Definition: sort.hpp:40
int id
Definition: sort.hpp:23
TrackingBox()
Definition: sort.hpp:25
std::vector< TrackingBox > frameTrackingResult
Definition: sort.hpp:53
std::vector< std::vector< double > > centroid_dist_matrix
Definition: sort.hpp:45
int frame
Definition: sort.hpp:20
cv::Rect_< float > box
Definition: sort.hpp:24
std::set< int > matchedItems
Definition: sort.hpp:50
std::set< int > allItems
Definition: sort.hpp:49
int _max_age
Definition: sort.hpp:59
int _min_hits
Definition: sort.hpp:58
float confidence
Definition: sort.hpp:21