-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathostrack_mnn.h
92 lines (61 loc) · 1.85 KB
/
ostrack_mnn.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by zxiong on 23-3-31.
//
#ifndef OSTRACK_H
#define OSTRACK_H
#include <vector>
#include <map>
#include <memory>
#include <MNN/ImageProcess.hpp>
#include <MNN/Interpreter.hpp>
#include <MNN/Matrix.h>
#include <MNN/Tensor.hpp>
#include "opencv2/opencv.hpp"
struct DrBBox {
float x0;
float y0;
float x1;
float y1;
};
struct DrOBB {
DrBBox box;
float score;
int class_id;
};
struct Config {
std::vector<float> window;
float template_factor = 2.0;
float search_factor = 4.0; // 5.0
float template_size = 128; //192
float search_size = 256; // 384
float stride = 16;
int feat_sz = 16; // 24
};
class OSTrack {
public:
OSTrack(const char *model_path);
~OSTrack();
void init(const cv::Mat &img, DrOBB bbox);
const DrOBB &track(const cv::Mat &img);
// state dynamic
DrBBox state;
// config static
Config cfg;
private:
void map_box_back(DrBBox &pred_box, float resize_factor);
void clip_box(DrBBox &box, int height, int wight, int margin);
void cal_bbox(MNN::Tensor &scores_tensor, MNN::Tensor &offsets_tensor, MNN::Tensor &sizes_tensor, DrBBox &pred_box, float &max_score, float resize_factor);
void sample_target(const cv::Mat &im, cv::Mat &croped, DrBBox target_bb, float search_area_factor, int output_sz, float &resize_factor);
const float means[3] = {0.406*255, 0.485*255, 0.456*255}; // BGR
const float norms[3] = {1/(0.225*255), 1/(0.229*255), 1/(0.224*255)}; // BGR
std::unique_ptr<MNN::Interpreter> mnn_net = nullptr;
MNN::Tensor *x = nullptr;
MNN::Tensor *z = nullptr;
MNN::Session *session = nullptr;
MNN::ScheduleConfig net_config;
cv::Mat z_patch;
MNN::CV::ImageProcess::Config config;
std::unique_ptr<MNN::CV::ImageProcess> pretreat;
DrOBB object_box;
};
#endif