Loading...
Searching...
No Matches
sort.hpp
Go to the documentation of this file.
// © OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "KalmanTracker.h"
#include "Hungarian.h"
#include <iostream>
#include <fstream>
#include <iomanip> // to format image names using setw() and setfill()
#include <set>
#include <algorithm> // for std::sort
#include "opencv2/video/tracking.hpp"
#include "opencv2/highgui/highgui.hpp"
#ifndef _OPENCV_KCFTRACKER_HPP_
#define _OPENCV_KCFTRACKER_HPP_
#endif
#pragma once
typedef struct TrackingBox
{
int frame = 0;
float confidence = 0;
int classId = 0;
int id = 0;
cv::Rect_<float> box = cv::Rect_<float>(0.0, 0.0, 0.0, 0.0);
TrackingBox() {}
TrackingBox(int _frame, float _confidence, int _classId, int _id) : frame(_frame), confidence(_confidence), classId(_classId), id(_id) {}
} TrackingBox;
class SortTracker
{
public:
// Constructor
SortTracker(int max_age = 50, int min_hits = 5, int max_missed = 7, double min_iou = 0.1, double nms_iou_thresh = 0.5, double min_conf = 0.3);
// Initialize tracker
// Update position based on the new frame
void update(std::vector<cv::Rect> detection, int frame_count, double image_diagonal, std::vector<float> confidences, std::vector<int> classIds);
static double GetIOU(cv::Rect_<float> bb_test, cv::Rect_<float> bb_gt);
double GetCentroidsDistance(cv::Rect_<float> bb_test, cv::Rect_<float> bb_gt);
std::vector<KalmanTracker> trackers;
double max_centroid_dist_norm = 0.3;
std::vector<cv::Rect_<float>> predictedBoxes;
std::vector<std::vector<double>> cost_matrix;
std::vector<int> assignment;
std::set<int> unmatchedDetections;
std::set<int> unmatchedTrajectories;
std::set<int> allItems;
std::set<int> matchedItems;
std::vector<cv::Point> matchedPairs;
std::vector<TrackingBox> frameTrackingResult;
std::vector<int> dead_trackers_id;
unsigned int trkNum = 0;
unsigned int detNum = 0;
int _min_hits;
int _max_age;
int _max_missed;
double _min_iou;
double _nms_iou_thresh;
double _min_conf;
unsigned int _next_id;
bool alive_tracker;
};
Hungarian.h
KalmanTracker.h
SortTracker::trkNum
unsigned int trkNum
Definition sort.hpp:60
SortTracker::max_centroid_dist_norm
double max_centroid_dist_norm
Definition sort.hpp:46
SortTracker::dead_trackers_id
std::vector< int > dead_trackers_id
Definition sort.hpp:58
SortTracker::_min_iou
double _min_iou
Definition sort.hpp:65
SortTracker::frameTrackingResult
std::vector< TrackingBox > frameTrackingResult
Definition sort.hpp:57
SortTracker::unmatchedDetections
std::set< int > unmatchedDetections
Definition sort.hpp:51
SortTracker::cost_matrix
std::vector< std::vector< double > > cost_matrix
Definition sort.hpp:49
SortTracker::_max_age
int _max_age
Definition sort.hpp:63
SortTracker::_nms_iou_thresh
double _nms_iou_thresh
Definition sort.hpp:66
SortTracker::_min_conf
double _min_conf
Definition sort.hpp:67
SortTracker::matchedPairs
std::vector< cv::Point > matchedPairs
Definition sort.hpp:55
SortTracker::SortTracker
SortTracker(int max_age=50, int min_hits=5, int max_missed=7, double min_iou=0.1, double nms_iou_thresh=0.5, double min_conf=0.3)
Definition sort.cpp:10
SortTracker::GetCentroidsDistance
double GetCentroidsDistance(cv::Rect_< float > bb_test, cv::Rect_< float > bb_gt)
Definition sort.cpp:35
SortTracker::trackers
std::vector< KalmanTracker > trackers
Definition sort.hpp:44
SortTracker::predictedBoxes
std::vector< cv::Rect_< float > > predictedBoxes
Definition sort.hpp:48
SortTracker::_min_hits
int _min_hits
Definition sort.hpp:62
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:84
SortTracker::allItems
std::set< int > allItems
Definition sort.hpp:53
SortTracker::detNum
unsigned int detNum
Definition sort.hpp:61
SortTracker::alive_tracker
bool alive_tracker
Definition sort.hpp:69
SortTracker::assignment
std::vector< int > assignment
Definition sort.hpp:50
SortTracker::matchedItems
std::set< int > matchedItems
Definition sort.hpp:54
SortTracker::unmatchedTrajectories
std::set< int > unmatchedTrajectories
Definition sort.hpp:52
SortTracker::_max_missed
int _max_missed
Definition sort.hpp:64
SortTracker::_next_id
unsigned int _next_id
Definition sort.hpp:68
SortTracker::GetIOU
static double GetIOU(cv::Rect_< float > bb_test, cv::Rect_< float > bb_gt)
Definition sort.cpp:23
TrackingBox
Definition sort.hpp:23
TrackingBox::box
cv::Rect_< float > box
Definition sort.hpp:28
TrackingBox::frame
int frame
Definition sort.hpp:24
TrackingBox::TrackingBox
TrackingBox()
Definition sort.hpp:29
TrackingBox::confidence
float confidence
Definition sort.hpp:25
TrackingBox::TrackingBox
TrackingBox(int _frame, float _confidence, int _classId, int _id)
Definition sort.hpp:30
TrackingBox::classId
int classId
Definition sort.hpp:26
TrackingBox::id
int id
Definition sort.hpp:27