Initial setup for CLion
This commit is contained in:
58
ANSMOT/ByteTrackNCNN/include/NCNNBYTETracker.h
Normal file
58
ANSMOT/ByteTrackNCNN/include/NCNNBYTETracker.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include "NCNNSTrack.h"
|
||||
#include <NCNNObject.h>
|
||||
#include <chrono>
|
||||
namespace ByteTrackNCNN {
|
||||
class BYTETracker
|
||||
{
|
||||
public:
|
||||
BYTETracker(int frame_rate = 30, int track_buffer = 30);
|
||||
~BYTETracker();
|
||||
|
||||
std::vector<STrack> update(const std::vector<ByteTrackNCNN::Object>& objects);
|
||||
//cv::Scalar get_color(int idx);
|
||||
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<STrack*> joint_stracks(std::vector<STrack*>& tlista, std::vector<STrack>& tlistb);
|
||||
std::vector<STrack> joint_stracks(std::vector<STrack>& tlista, std::vector<STrack>& tlistb);
|
||||
|
||||
std::vector<STrack> sub_stracks(std::vector<STrack>& tlista, std::vector<STrack>& tlistb);
|
||||
void remove_duplicate_stracks(std::vector<STrack>& resa, std::vector<STrack>& resb, std::vector<STrack>& stracksa, std::vector<STrack>& stracksb);
|
||||
|
||||
void linear_assignment(std::vector< std::vector<float> >& cost_matrix, int cost_matrix_size, int cost_matrix_size_size, float thresh,
|
||||
std::vector< std::vector<int> >& matches, std::vector<int>& unmatched_a, std::vector<int>& unmatched_b);
|
||||
std::vector< std::vector<float> > iou_distance(std::vector<STrack*>& atracks, std::vector<STrack>& btracks, int& dist_size, int& dist_size_size);
|
||||
std::vector< std::vector<float> > iou_distance(std::vector<STrack>& atracks, std::vector<STrack>& btracks);
|
||||
std::vector< std::vector<float> > ious(std::vector< std::vector<float> >& atlbrs, std::vector< std::vector<float> >& btlbrs);
|
||||
|
||||
double lapjv(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);
|
||||
|
||||
void estimateFrameRate();
|
||||
|
||||
private:
|
||||
|
||||
float track_thresh;
|
||||
float high_thresh;
|
||||
float match_thresh;
|
||||
int frame_id;
|
||||
int max_time_lost;
|
||||
int track_id_count;
|
||||
int track_buffer_;
|
||||
|
||||
// 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<STrack> tracked_stracks;
|
||||
std::vector<STrack> lost_stracks;
|
||||
std::vector<STrack> removed_stracks;
|
||||
ByteTrackNCNN::ByteKalmanFilter kalman_filter;
|
||||
};
|
||||
|
||||
}
|
||||
28
ANSMOT/ByteTrackNCNN/include/NCNNBytekalmanFilter.h
Normal file
28
ANSMOT/ByteTrackNCNN/include/NCNNBytekalmanFilter.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include "NCNNdataType.h"
|
||||
namespace ByteTrackNCNN {
|
||||
class ByteKalmanFilter
|
||||
{
|
||||
public:
|
||||
static const double chi2inv95[10];
|
||||
ByteKalmanFilter();
|
||||
KAL_DATA initiate(const DETECTBOX& measurement);
|
||||
void predict(KAL_MEAN& mean, KAL_COVA& covariance);
|
||||
KAL_HDATA project(const KAL_MEAN& mean, const KAL_COVA& covariance);
|
||||
KAL_DATA update(const KAL_MEAN& mean,
|
||||
const KAL_COVA& covariance,
|
||||
const DETECTBOX& measurement);
|
||||
|
||||
Eigen::Matrix<float, 1, -1> gating_distance(
|
||||
const KAL_MEAN& mean,
|
||||
const KAL_COVA& covariance,
|
||||
const std::vector<DETECTBOX>& measurements,
|
||||
bool only_position = false);
|
||||
|
||||
private:
|
||||
Eigen::Matrix<float, 8, 8, Eigen::RowMajor> _motion_mat;
|
||||
Eigen::Matrix<float, 4, 8, Eigen::RowMajor> _update_mat;
|
||||
float _std_weight_position;
|
||||
float _std_weight_velocity;
|
||||
};
|
||||
}
|
||||
25
ANSMOT/ByteTrackNCNN/include/NCNNObject.h
Normal file
25
ANSMOT/ByteTrackNCNN/include/NCNNObject.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "NCNNRect.h"
|
||||
namespace ByteTrackNCNN
|
||||
{
|
||||
struct Object
|
||||
{
|
||||
ByteTrackNCNN::Rect<float> box; //left, top, right, bottom
|
||||
int label;
|
||||
float confidence;
|
||||
float left;
|
||||
float top;
|
||||
float right;
|
||||
float bottom;
|
||||
std::string object_id;
|
||||
|
||||
Object(const ByteTrackNCNN::Rect<float>& _box,
|
||||
const int& _label,
|
||||
const float& _confidence,
|
||||
const float& _left,
|
||||
const float& _top,
|
||||
const float& _right,
|
||||
const float& _bottom,
|
||||
const std::string& _object_id);
|
||||
};
|
||||
}
|
||||
51
ANSMOT/ByteTrackNCNN/include/NCNNRect.h
Normal file
51
ANSMOT/ByteTrackNCNN/include/NCNNRect.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include "Eigen/Dense"
|
||||
namespace ByteTrackNCNN
|
||||
{
|
||||
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);
|
||||
}
|
||||
63
ANSMOT/ByteTrackNCNN/include/NCNNSTrack.h
Normal file
63
ANSMOT/ByteTrackNCNN/include/NCNNSTrack.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include "NCNNBytekalmanFilter.h"
|
||||
#include <unordered_map>
|
||||
namespace ByteTrackNCNN {
|
||||
enum TrackState { New = 0, Tracked, Lost, Removed };
|
||||
class STrack
|
||||
{
|
||||
public:
|
||||
STrack(std::vector<float> tlwh_, float _score,
|
||||
int _class_id, float _left, float _top,
|
||||
float _right, float _bottom, std::string _object_id);
|
||||
~STrack();
|
||||
|
||||
std::vector<float> static tlbr_to_tlwh(std::vector<float>& tlbr);
|
||||
void static multi_predict(std::vector<STrack*>& stracks, ByteTrackNCNN::ByteKalmanFilter& kalman_filter);
|
||||
void static_tlwh();
|
||||
void static_tlbr();
|
||||
std::vector<float> tlwh_to_xyah(std::vector<float> tlwh_tmp);
|
||||
std::vector<float> to_xyah();
|
||||
void mark_lost();
|
||||
void mark_removed();
|
||||
int next_id();
|
||||
int end_frame();
|
||||
void reset_count();
|
||||
|
||||
void activate(ByteTrackNCNN::ByteKalmanFilter& kalman_filter, int frame_id);
|
||||
void activate(ByteTrackNCNN::ByteKalmanFilter& kalman_filter, int frame_id, int track_id_count);
|
||||
void re_activate(STrack& new_track, int frame_id, bool new_id = false);
|
||||
void update(STrack& new_track, int frame_id);
|
||||
|
||||
public:
|
||||
bool is_activated;
|
||||
int track_id;
|
||||
int state;
|
||||
int count;
|
||||
|
||||
std::vector<float> _tlwh;
|
||||
std::vector<float> tlwh;
|
||||
std::vector<float> tlbr;
|
||||
float left; // left, top, right, bottom (original bounding of detected object)
|
||||
float top;
|
||||
float right;
|
||||
float bottom;
|
||||
int frame_id;
|
||||
int tracklet_len;
|
||||
int start_frame;
|
||||
std::string object_id;
|
||||
|
||||
KAL_MEAN mean;
|
||||
KAL_COVA covariance;
|
||||
float score;
|
||||
int class_id;
|
||||
|
||||
private:
|
||||
ByteTrackNCNN::ByteKalmanFilter kalman_filter;
|
||||
std::unordered_map<int, float> class_id_scores_;
|
||||
int detection_count_;
|
||||
bool class_id_locked_;
|
||||
static const int CLASS_ID_LOCK_FRAMES = 10;
|
||||
void voteClassId(int new_class_id, float score);
|
||||
};
|
||||
}
|
||||
|
||||
52
ANSMOT/ByteTrackNCNN/include/NCNNdataType.h
Normal file
52
ANSMOT/ByteTrackNCNN/include/NCNNdataType.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*!
|
||||
@Description : https://github.com/shaoshengsong/
|
||||
@Author : shaoshengsong
|
||||
@Date : 2022-09-21 05:49:06
|
||||
*/
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
namespace ByteTrackNCNN {
|
||||
const int k_feature_dim = 512;//feature dim
|
||||
|
||||
const std::string k_feature_model_path = "feature.onnx";
|
||||
const std::string k_detect_model_path = "yolov5s.onnx";
|
||||
|
||||
|
||||
typedef Eigen::Matrix<float, 1, 4, Eigen::RowMajor> DETECTBOX;
|
||||
typedef Eigen::Matrix<float, -1, 4, Eigen::RowMajor> DETECTBOXSS;
|
||||
typedef Eigen::Matrix<float, 1, k_feature_dim, Eigen::RowMajor> FEATURE;
|
||||
typedef Eigen::Matrix<float, Eigen::Dynamic, k_feature_dim, Eigen::RowMajor> FEATURESS;
|
||||
//typedef std::vector<FEATURE> FEATURESS;
|
||||
|
||||
//Kalmanfilter
|
||||
//typedef Eigen::Matrix<float, 8, 8, Eigen::RowMajor> KAL_FILTER;
|
||||
typedef Eigen::Matrix<float, 1, 8, Eigen::RowMajor> KAL_MEAN;
|
||||
typedef Eigen::Matrix<float, 8, 8, Eigen::RowMajor> KAL_COVA;
|
||||
typedef Eigen::Matrix<float, 1, 4, Eigen::RowMajor> KAL_HMEAN;
|
||||
typedef Eigen::Matrix<float, 4, 4, Eigen::RowMajor> KAL_HCOVA;
|
||||
using KAL_DATA = std::pair<KAL_MEAN, KAL_COVA>;
|
||||
using KAL_HDATA = std::pair<KAL_HMEAN, KAL_HCOVA>;
|
||||
|
||||
//main
|
||||
using RESULT_DATA = std::pair<int, DETECTBOX>;
|
||||
|
||||
//tracker:
|
||||
using TRACKER_DATA = std::pair<int, FEATURESS>;
|
||||
using MATCH_DATA = std::pair<int, int>;
|
||||
typedef struct t {
|
||||
std::vector<MATCH_DATA> matches;
|
||||
std::vector<int> unmatched_tracks;
|
||||
std::vector<int> unmatched_detections;
|
||||
}TRACHER_MATCHD;
|
||||
|
||||
//linear_assignment:
|
||||
typedef Eigen::Matrix<float, -1, -1, Eigen::RowMajor> DYNAMICM;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
65
ANSMOT/ByteTrackNCNN/include/NCNNlapjv.h
Normal file
65
ANSMOT/ByteTrackNCNN/include/NCNNlapjv.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef LAPJV_H
|
||||
#define LAPJV_H
|
||||
namespace ByteTrackNCNN
|
||||
{
|
||||
#define LARGE 1000000
|
||||
|
||||
#if !defined TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#if !defined FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define NEW(x, t, n) if ((x = (t *)malloc(sizeof(t) * (n))) == 0) { return -1; }
|
||||
#define FREE(x) if (x != 0) { free(x); x = 0; }
|
||||
#define SWAP_INDICES(a, b) { int_t _temp_index = a; a = b; b = _temp_index; }
|
||||
|
||||
#if 0
|
||||
#include <assert.h>
|
||||
#define ASSERT(cond) assert(cond)
|
||||
#define PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||
#define PRINT_COST_ARRAY(a, n) \
|
||||
while (1) { \
|
||||
printf(#a" = ["); \
|
||||
if ((n) > 0) { \
|
||||
printf("%f", (a)[0]); \
|
||||
for (uint_t j = 1; j < n; j++) { \
|
||||
printf(", %f", (a)[j]); \
|
||||
} \
|
||||
} \
|
||||
printf("]\n"); \
|
||||
break; \
|
||||
}
|
||||
#define PRINT_INDEX_ARRAY(a, n) \
|
||||
while (1) { \
|
||||
printf(#a" = ["); \
|
||||
if ((n) > 0) { \
|
||||
printf("%d", (a)[0]); \
|
||||
for (uint_t j = 1; j < n; j++) { \
|
||||
printf(", %d", (a)[j]); \
|
||||
} \
|
||||
} \
|
||||
printf("]\n"); \
|
||||
break; \
|
||||
}
|
||||
#else
|
||||
#define ASSERT(cond)
|
||||
#define PRINTF(fmt, ...)
|
||||
#define PRINT_COST_ARRAY(a, n)
|
||||
#define PRINT_INDEX_ARRAY(a, n)
|
||||
#endif
|
||||
|
||||
|
||||
typedef signed int int_t;
|
||||
typedef unsigned int uint_t;
|
||||
typedef double cost_t;
|
||||
typedef char boolean;
|
||||
typedef enum fp_t { FP_1 = 1, FP_2 = 2, FP_DYNAMIC = 3 } fp_t;
|
||||
|
||||
extern int_t lapjv_internal(
|
||||
const uint_t n, cost_t* cost[],
|
||||
int_t* x, int_t* y);
|
||||
|
||||
}
|
||||
#endif // LAPJV_H
|
||||
Reference in New Issue
Block a user