Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion botsort/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ file(GLOB_RECURSE SOURCES "${PROJECT_SOURCE_DIR}/src/*.cpp")
add_library(${PROJECT_NAME} SHARED ${SOURCES})

# Set include directories
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

# Find and link OpenCV
find_package(OpenCV REQUIRED)
Expand Down
21 changes: 13 additions & 8 deletions botsort/include/BoTSORT.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#pragma once

#include <string>
#include <variant>

#include "GlobalMotionCompensation.h"
#include "GmcParams.h"
#include "ReID.h"
#include "ReIDParams.h"
#include "TrackerParams.h"
#include "track.h"

template<typename T>
using Config = std::variant<T, std::string, std::monostate>;

class BoTSORT
{
public:
explicit BoTSORT(const std::string &tracker_config_path,
const std::string &gmc_config_path = "",
const std::string &reid_config_path = "",
explicit BoTSORT(const Config<TrackerParams> &tracker_config,
const Config<GMC_Params> &gmc_config = {},
const Config<ReIDParams> &reid_config = {},
const std::string &reid_onnx_model_path = "");

~BoTSORT() = default;


Expand Down Expand Up @@ -79,14 +86,12 @@ class BoTSORT
std::vector<std::shared_ptr<Track>> &tracks_list_a,
std::vector<std::shared_ptr<Track>> &tracks_list_b);


/**
* @brief Load tracker parameters from the given config file
* @brief Load tracker parameters from the given config
*
* @param config_path Path to the config directory
* @param config Configuration to load
*/
void _load_params_from_config(const std::string &config_path);

void _load_params_from_config(const TrackerParams &config);

private:
std::string _gmc_method_name;
Expand Down
37 changes: 13 additions & 24 deletions botsort/include/GlobalMotionCompensation.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// .clang-format off
#include "DataType.h"
#include "GmcParams.h"
// .clang-format on

#include <opencv2/core/eigen.hpp>
Expand All @@ -17,16 +18,6 @@
#include <opencv2/videostab/global_motion.hpp>


enum GMC_Method
{
ORB = 0,
ECC,
SparseOptFlow,
OptFlowModified,
OpenCV_VideoStab
};


class GMC_Algorithm
{
public:
Expand All @@ -39,13 +30,13 @@ class GMC_Algorithm
class ORB_GMC : public GMC_Algorithm
{
public:
explicit ORB_GMC(const std::string &config_path);
explicit ORB_GMC(const ORB_Params &orb_config);
HomographyMatrix apply(const cv::Mat &frame_raw,
const std::vector<Detection> &detections) override;


private:
void _load_params_from_config(const std::string &config_path);
void _load_params_from_config(const ORB_Params &orb_config);


private:
Expand All @@ -67,13 +58,13 @@ class ORB_GMC : public GMC_Algorithm
class ECC_GMC : public GMC_Algorithm
{
public:
explicit ECC_GMC(const std::string &config_path);
explicit ECC_GMC(const ECC_Params &config);
HomographyMatrix apply(const cv::Mat &frame_raw,
const std::vector<Detection> &detections) override;


private:
void _load_params_from_config(const std::string &config_dir);
void _load_params_from_config(const ECC_Params &config);


private:
Expand All @@ -91,13 +82,13 @@ class ECC_GMC : public GMC_Algorithm
class SparseOptFlow_GMC : public GMC_Algorithm
{
public:
explicit SparseOptFlow_GMC(const std::string &config_path);
explicit SparseOptFlow_GMC(const SparseOptFlow_Params &config);
HomographyMatrix apply(const cv::Mat &frame_raw,
const std::vector<Detection> &detections) override;


private:
void _load_params_from_config(const std::string &config_dir);
void _load_params_from_config(const SparseOptFlow_Params &config);


private:
Expand All @@ -119,13 +110,13 @@ class SparseOptFlow_GMC : public GMC_Algorithm
class OptFlowModified_GMC : public GMC_Algorithm
{
public:
explicit OptFlowModified_GMC(const std::string &config_path);
explicit OptFlowModified_GMC(const OptFlowModified_Params &config);
HomographyMatrix apply(const cv::Mat &frame_raw,
const std::vector<Detection> &detections) override;


private:
void _load_params_from_config(const std::string &config_dir);
void _load_params_from_config(const OptFlowModified_Params &config);


private:
Expand All @@ -137,13 +128,13 @@ class OptFlowModified_GMC : public GMC_Algorithm
class OpenCV_VideoStab_GMC : public GMC_Algorithm
{
public:
explicit OpenCV_VideoStab_GMC(const std::string &config_path);
explicit OpenCV_VideoStab_GMC(const OpenCV_VideoStab_GMC_Params &config);
HomographyMatrix apply(const cv::Mat &frame_raw,
const std::vector<Detection> &detections) override;


private:
void _load_params_from_config(const std::string &config_dir);
void _load_params_from_config(const OpenCV_VideoStab_GMC_Params &config);


private:
Expand All @@ -167,11 +158,9 @@ class GlobalMotionCompensation
/**
* @brief Construct a new Global Motion Compensation object
*
* @param method GMC_Method enum member for GMC algorithm to use
* @param config_dir Directory containing config files for GMC algorithm
* @param gmc_params Paramerters for GMC algorithm
*/
explicit GlobalMotionCompensation(GMC_Method method,
const std::string &config_path);
explicit GlobalMotionCompensation(const GMC_Params &gmc_params);
~GlobalMotionCompensation() = default;

/**
Expand Down
68 changes: 68 additions & 0 deletions botsort/include/GmcParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once

#include <string>
#include <variant>

enum GMC_Method
{
ORB = 0,
ECC,
SparseOptFlow,
OptFlowModified,
OpenCV_VideoStab
};

struct ORB_Params
{
float downscale{2.f};
float inlier_ratio{0.5f};
float ransac_conf{.99f};
long ransac_max_iters{500};
};

struct ECC_Params
{
float downscale{5.f};
long max_iterations{100};
float termination_eps{1e-6};
};

struct SparseOptFlow_Params
{
long max_corners{1000};
long block_size{3};
long ransac_max_iters{500};
double quality_level{0.01};
double k{0.04};
double min_distance{1.0};
float downscale{2.0f};
float inlier_ratio{0.5f};
float ransac_conf{0.99f};
bool use_harris_detector{false};
};

struct OptFlowModified_Params
{
float downscale{2.0f};
};

struct OpenCV_VideoStab_GMC_Params
{
float downscale{2.0f};
float num_features{4000};
bool detection_masking{true};
};

struct GMC_Params
{
using MethodParams =
std::variant<ORB_Params, ECC_Params, SparseOptFlow_Params,
OptFlowModified_Params, OpenCV_VideoStab_GMC_Params,
std::monostate>;

GMC_Method method_;
MethodParams method_params_;

static GMC_Params load_config(GMC_Method method,
const std::string &config_path);
};
92 changes: 76 additions & 16 deletions botsort/include/INIReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,45 +359,74 @@ class INIReader
}

// Return the list of sections found in ini file
const std::set<std::string> &Sections() const;
[[nodiscard]] const std::set<std::string> &Sections() const;

// Get a string value from INI file, returning default_value if not found.
std::string Get(const std::string &section, const std::string &name,
const std::string &default_value) const;
[[nodiscard]] std::string Get(const std::string &section,
const std::string &name,
const std::string &default_value) const;


// Get a string value from INI file, return nullopt if not found.
std::optional<std::string> Get(const std::string &section,
const std::string &name) const;
[[nodiscard]] std::optional<std::string> Get(const std::string &section,
const std::string &name) const;


// Get an integer (long) value from INI file, returning default_value if
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
long GetInteger(const std::string &section, const std::string &name,
long default_value) const;
[[nodiscard]] long GetInteger(const std::string &section,
const std::string &name,
long default_value) const;

// Get a real (floating point double) value from INI file, returning
// default_value if not found or not a valid floating point value
// according to strtod().
double GetReal(const std::string &section, const std::string &name,
double default_value) const;
[[nodiscard]] double GetReal(const std::string &section,
const std::string &name,
double default_value) const;

// Get a single precision floating point number value from INI file, returning
// default_value if not found or not a valid floating point value
// according to strtof().
float GetFloat(const std::string &section, const std::string &name,
float default_value) const;
[[nodiscard]] float GetFloat(const std::string &section,
const std::string &name,
float default_value) const;

// Get a boolean value from INI file, returning default_value if not found or if
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
// and valid false values are "false", "no", "off", "0" (not case sensitive).
bool GetBoolean(const std::string &section, const std::string &name,
bool default_value) const;
[[nodiscard]] bool GetBoolean(const std::string &section,
const std::string &name,
bool default_value) const;

template<typename T>
std::vector<T> GetList(const std::string &section,
const std::string &name) const;

[[nodiscard]] std::vector<T> GetList(const std::string &section,
const std::string &name) const;

// Load a string value from INI file, returning its value if successfully
// loaded, or leave value unchanged
void LoadString(const std::string &section, const std::string &name,
std::string &value) const;

// Load an integer (long) value from INI file, returning its value if
// successfully loaded, or leave value unchanged
void LoadInteger(const std::string &section, const std::string &name,
long &value) const;

// Load a real (floating point double) value from INI file, returning its
// value if successfully loaded, or leave value unchanged
void LoadReal(const std::string &section, const std::string &name,
double &value) const;

// Load a single precision floating point number value from INI file, returning
// its value if successfully loaded, or leave value unchanged
void LoadFloat(const std::string &section, const std::string &name,
float &value) const;

// Load a boolean value from INI file, returning its value if successfully
// loaded, or leave value unchanged
void LoadBoolean(const std::string &section, const std::string &name,
bool &value) const;

protected:
int _error;
Expand Down Expand Up @@ -568,4 +597,35 @@ std::vector<T> INIReader::GetList(const std::string &section,
return list_items;
}

inline void INIReader::LoadString(const std::string &section,
const std::string &name,
std::string &value) const
{
value = Get(section, name, value);
}

inline void INIReader::LoadInteger(const std::string &section,
const std::string &name, long &value) const
{
value = GetInteger(section, name, value);
}

inline void INIReader::LoadReal(const std::string &section,
const std::string &name, double &value) const
{
value = GetReal(section, name, value);
}

inline void INIReader::LoadFloat(const std::string &section,
const std::string &name, float &value) const
{
value = GetFloat(section, name, value);
}

inline void INIReader::LoadBoolean(const std::string &section,
const std::string &name, bool &value) const
{
value = GetBoolean(section, name, value);
}

#endif// __INIREADER__
Loading