Initial setup for CLion
This commit is contained in:
86
ANSMOT/ByteTrack/include/BYTETracker.h
Normal file
86
ANSMOT/ByteTrack/include/BYTETracker.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
#include "STrack.h"
|
||||
#include "lapjv.h"
|
||||
#include "Object.h"
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace ByteTrack
|
||||
{
|
||||
class BYTETracker
|
||||
{
|
||||
public:
|
||||
using STrackPtr = std::shared_ptr<STrack>;
|
||||
|
||||
BYTETracker(const int& frame_rate = 30,
|
||||
const int& track_buffer = 30,
|
||||
const float& track_thresh = 0.5,
|
||||
const float& high_thresh = 0.6,
|
||||
const float& match_thresh = 0.8);
|
||||
~BYTETracker();
|
||||
std::vector<STrackPtr> update(const std::vector<Object>& objects);
|
||||
void update_parameters(int frameRate = 30, int trackBuffer = 30, double trackThreshold = 0.5, double highThreshold = 0.6, double matchThresold = 0.8, bool autoFrameRate = false);
|
||||
float getEstimatedFps() const;
|
||||
|
||||
private:
|
||||
std::vector<STrackPtr> jointStracks(const std::vector<STrackPtr> &a_tlist,
|
||||
const std::vector<STrackPtr> &b_tlist) const;
|
||||
|
||||
std::vector<STrackPtr> subStracks(const std::vector<STrackPtr> &a_tlist,
|
||||
const std::vector<STrackPtr> &b_tlist) const;
|
||||
|
||||
void removeDuplicateStracks(const std::vector<STrackPtr> &a_stracks,
|
||||
const std::vector<STrackPtr> &b_stracks,
|
||||
std::vector<STrackPtr> &a_res,
|
||||
std::vector<STrackPtr> &b_res) const;
|
||||
|
||||
void linearAssignment(const std::vector<std::vector<float>> &cost_matrix,
|
||||
const int &cost_matrix_size,
|
||||
const int &cost_matrix_size_size,
|
||||
const float &thresh,
|
||||
std::vector<std::vector<int>> &matches,
|
||||
std::vector<int> &b_unmatched,
|
||||
std::vector<int> &a_unmatched) const;
|
||||
|
||||
std::vector<std::vector<float>> calcIouDistance(const std::vector<STrackPtr> &a_tracks,
|
||||
const std::vector<STrackPtr> &b_tracks) const;
|
||||
|
||||
std::vector<std::vector<float>> calcIous(const std::vector<Rect<float>> &a_rect,
|
||||
const std::vector<Rect<float>> &b_rect) const;
|
||||
|
||||
double execLapjv(const std::vector<std::vector<float> > &cost,
|
||||
std::vector<int> &rowsol,
|
||||
std::vector<int> &colsol,
|
||||
bool extend_cost = false,
|
||||
float cost_limit = LONG_MAX,
|
||||
bool return_cost = true) const;
|
||||
|
||||
void estimateFrameRate();
|
||||
|
||||
private:
|
||||
float track_thresh_;
|
||||
float high_thresh_;
|
||||
float match_thresh_;
|
||||
size_t max_time_lost_;
|
||||
int track_buffer_;
|
||||
|
||||
size_t frame_id_;
|
||||
size_t track_id_count_;
|
||||
|
||||
// Frame rate auto-estimation
|
||||
bool auto_frame_rate_;
|
||||
float estimated_fps_;
|
||||
float time_scale_factor_;
|
||||
size_t fps_sample_count_;
|
||||
std::chrono::steady_clock::time_point last_update_time_;
|
||||
bool has_last_update_time_;
|
||||
|
||||
std::vector<STrackPtr> tracked_stracks_;
|
||||
std::vector<STrackPtr> lost_stracks_;
|
||||
std::vector<STrackPtr> removed_stracks_;
|
||||
};
|
||||
}
|
||||
36
ANSMOT/ByteTrack/include/KalmanFilter.h
Normal file
36
ANSMOT/ByteTrack/include/KalmanFilter.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "Eigen/Dense"
|
||||
#include "Rect.h"
|
||||
namespace ByteTrack
|
||||
{
|
||||
class KalmanFilter
|
||||
{
|
||||
public:
|
||||
using DetectBox = Xyah<float>;
|
||||
|
||||
using StateMean = Eigen::Matrix<float, 1, 8, Eigen::RowMajor>;
|
||||
using StateCov = Eigen::Matrix<float, 8, 8, Eigen::RowMajor>;
|
||||
|
||||
using StateHMean = Eigen::Matrix<float, 1, 4, Eigen::RowMajor>;
|
||||
using StateHCov = Eigen::Matrix<float, 4, 4, Eigen::RowMajor>;
|
||||
|
||||
KalmanFilter(const float& std_weight_position = 1. / 20,
|
||||
const float& std_weight_velocity = 1. / 160);
|
||||
|
||||
void initiate(StateMean& mean, StateCov& covariance, const DetectBox& measurement);
|
||||
|
||||
void predict(StateMean& mean, StateCov& covariance);
|
||||
|
||||
void update(StateMean& mean, StateCov& covariance, const DetectBox& measurement);
|
||||
|
||||
private:
|
||||
float std_weight_position_;
|
||||
float std_weight_velocity_;
|
||||
|
||||
Eigen::Matrix<float, 8, 8, Eigen::RowMajor> motion_mat_;
|
||||
Eigen::Matrix<float, 4, 8, Eigen::RowMajor> update_mat_;
|
||||
|
||||
void project(StateHMean &projected_mean, StateHCov &projected_covariance,
|
||||
const StateMean& mean, const StateCov& covariance);
|
||||
};
|
||||
}
|
||||
24
ANSMOT/ByteTrack/include/Object.h
Normal file
24
ANSMOT/ByteTrack/include/Object.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "Rect.h"
|
||||
namespace ByteTrack
|
||||
{
|
||||
struct Object
|
||||
{
|
||||
Rect<float> rect;
|
||||
int label;
|
||||
float prob;
|
||||
float left;
|
||||
float top;
|
||||
float right;
|
||||
float bottom;
|
||||
std::string object_id;
|
||||
|
||||
Object(const Rect<float> &_rect,
|
||||
const int &_label,
|
||||
const float &_prob, const float& _left,
|
||||
const float& _top,
|
||||
const float& _right,
|
||||
const float& _bottom,
|
||||
const std::string& _object_id);
|
||||
};
|
||||
}
|
||||
51
ANSMOT/ByteTrack/include/Rect.h
Normal file
51
ANSMOT/ByteTrack/include/Rect.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include "Eigen/Dense"
|
||||
namespace ByteTrack
|
||||
{
|
||||
template<typename T>
|
||||
using Tlwh = Eigen::Matrix<T, 1, 4, Eigen::RowMajor>;
|
||||
|
||||
template<typename T>
|
||||
using Tlbr = Eigen::Matrix<T, 1, 4, Eigen::RowMajor>;
|
||||
|
||||
template<typename T>
|
||||
using Xyah = Eigen::Matrix<T, 1, 4, Eigen::RowMajor>;
|
||||
|
||||
template<typename T>
|
||||
class Rect
|
||||
{
|
||||
public:
|
||||
Tlwh<T> tlwh;
|
||||
|
||||
Rect() = default;
|
||||
Rect(const T &x, const T &y, const T &width, const T &height);
|
||||
|
||||
~Rect();
|
||||
|
||||
const T &x() const;
|
||||
const T &y() const;
|
||||
const T &width() const;
|
||||
const T &height() const;
|
||||
|
||||
T &x();
|
||||
T &y();
|
||||
T &width();
|
||||
T &height();
|
||||
|
||||
const T &tl_x() const;
|
||||
const T &tl_y() const;
|
||||
T br_x() const;
|
||||
T br_y() const;
|
||||
|
||||
Tlbr<T> getTlbr() const;
|
||||
Xyah<T> getXyah() const;
|
||||
|
||||
float calcIoU(const Rect<T>& other) const;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Rect<T> generate_rect_by_tlbr(const Tlbr<T>& tlbr);
|
||||
|
||||
template<typename T>
|
||||
Rect<T> generate_rect_by_xyah(const Xyah<T>& xyah);
|
||||
}
|
||||
72
ANSMOT/ByteTrack/include/STrack.h
Normal file
72
ANSMOT/ByteTrack/include/STrack.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "Rect.h"
|
||||
#include "KalmanFilter.h"
|
||||
#include <cstddef>
|
||||
#include <unordered_map>
|
||||
namespace ByteTrack
|
||||
{
|
||||
enum class STrackState {
|
||||
New = 0,
|
||||
Tracked = 1,
|
||||
Lost = 2,
|
||||
Removed = 3,
|
||||
};
|
||||
|
||||
class STrack
|
||||
{
|
||||
public:
|
||||
STrack(const Rect<float>& rect, const float& score,int _class_id, float _left, float _top,
|
||||
float _right, float _bottom, std::string _object_id);
|
||||
~STrack();
|
||||
|
||||
const Rect<float>& getRect() const;
|
||||
const STrackState& getSTrackState() const;
|
||||
|
||||
const bool& isActivated() const;
|
||||
const float& getScore() const;
|
||||
const size_t& getTrackId() const;
|
||||
const size_t& getFrameId() const;
|
||||
const size_t& getStartFrameId() const;
|
||||
const size_t& getTrackletLength() const;
|
||||
|
||||
void activate(const size_t& frame_id, const size_t& track_id);
|
||||
void reActivate(const STrack &new_track, const size_t &frame_id, const int &new_track_id = -1);
|
||||
|
||||
void predict();
|
||||
void update(const STrack &new_track, const size_t &frame_id);
|
||||
|
||||
void markAsLost();
|
||||
void markAsRemoved();
|
||||
|
||||
private:
|
||||
KalmanFilter kalman_filter_;
|
||||
KalmanFilter::StateMean mean_;
|
||||
KalmanFilter::StateCov covariance_;
|
||||
bool is_activated_;
|
||||
float score_;
|
||||
|
||||
Rect<float> rect_;
|
||||
STrackState state_;
|
||||
|
||||
size_t track_id_;
|
||||
size_t frame_id_;
|
||||
size_t start_frame_id_;
|
||||
size_t tracklet_len_;
|
||||
|
||||
void updateRect();
|
||||
public:
|
||||
float left; // left, top, right, bottom (original bounding of detected object)
|
||||
float top;
|
||||
float right;
|
||||
float bottom;
|
||||
std::string object_id;
|
||||
int class_id;
|
||||
private:
|
||||
std::unordered_map<int, float> class_id_scores_; // class_id -> accumulated detection score
|
||||
int detection_count_;
|
||||
bool class_id_locked_;
|
||||
static const int CLASS_ID_LOCK_FRAMES = 10;
|
||||
void voteClassId(int new_class_id, float score);
|
||||
};
|
||||
}
|
||||
6
ANSMOT/ByteTrack/include/lapjv.h
Normal file
6
ANSMOT/ByteTrack/include/lapjv.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
namespace ByteTrack
|
||||
{
|
||||
int lapjv_internal(const size_t n, double *cost[], int *x, int *y);
|
||||
}
|
||||
Reference in New Issue
Block a user