| #include <filesystem>
|
| #include <iostream>
|
| #include <fstream>
|
| #include<random>
|
| #include "BYTETracker.cpp"
|
| #include "GlobalMotionCompensation.cpp"
|
|
|
| #include <pybind11/pybind11.h>
|
| #include <pybind11/stl.h>
|
| #include <pybind11/eigen.h>
|
|
|
| namespace py = pybind11;
|
|
|
| PYBIND11_MODULE(adaptbytetrack, m) {
|
|
|
| py::class_<BYTETracker>(m, "BYTETracker")
|
| .def(py::init<int, int, float, float, bool > ())
|
| .def("update", &BYTETracker::update);
|
| }
|
|
|
| using namespace std;
|
| using namespace Eigen;
|
|
|
| MatrixXd read_txt(string file_name = "", char delim = ' ') {
|
| std::ifstream inRowCol(file_name);
|
| std::string lineRowCol;
|
| int nrows = 0;
|
| int ncols = 0;
|
| while (std::getline(inRowCol, lineRowCol)) {
|
| nrows++;
|
|
|
| std::vector<std::string> res;
|
| std::stringstream ss(lineRowCol);
|
| std::string element;
|
| ncols = 0;
|
| while (std::getline(ss, element, delim)) {
|
| ncols++;
|
| }
|
| }
|
| if (ncols == 0) {
|
| return MatrixXd(nrows, ncols);
|
| }
|
|
|
| std::ifstream in(file_name);
|
| std::string line;
|
| int row = 0;
|
| int col = 0;
|
| Eigen::MatrixXd res = Eigen::MatrixXd(nrows, ncols);
|
| if (in.is_open()) {
|
| while (std::getline(in, line)) {
|
| char *ptr = (char *) line.c_str();
|
| int len = line.length();
|
| col = 0;
|
| char *start = ptr;
|
| for (int i = 0; i < len; i++) {
|
| if (ptr[i] == delim) {
|
| res(row, col++) = atof(start);
|
| start = ptr + i + 1;
|
| }
|
| }
|
| res(row, col) = atof(start);
|
| row++;
|
| }
|
| in.close();
|
| }
|
| return res;
|
| }
|
|
|
| void write_results(const string &filename, const vector<vector<float>> &results) {
|
| std::ofstream file(filename);
|
| if (!file.is_open()) {
|
| std::cerr << "Error: cannot open file " << filename << std::endl;
|
| return;
|
| }
|
| for (const vector<float> &result: results) {
|
| int frame_id = result[0];
|
| int track_id = result[1];
|
| if (track_id < 0) continue;
|
| float x1 = result[2];
|
| float y1 = result[3];
|
| float w = result[4];
|
| float h = result[5];
|
| float s = 1;
|
| file << frame_id << ","
|
| << track_id << ","
|
| << std::fixed << std::setprecision(1)
|
| << x1 << "," << y1 << "," << w << "," << h << ","
|
| << std::setprecision(2) << s << ",-1,-1,-1\n";
|
| }
|
| file.close();
|
| std::cout << "Saved results to " << filename << std::endl;
|
| }
|
|
|
| cv::Scalar get_color(int idx) {
|
| idx = (idx + 1) * 50;
|
| int r = (37 * idx) % 255;
|
| int g = (17 * idx) % 255;
|
| int b = (29 * idx) % 255;
|
|
|
| return cv::Scalar(b, g, r);
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |