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