retinaface.h
2.18 KB
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
#ifndef RETINAFACE_H
#define RETINAFACE_H
#include<opencv2/opencv.hpp>
#include<MNN/Interpreter.hpp>
#include<MNN/ImageProcess.hpp>
#include<iostream>
#include<memory>
using namespace MNN;
using namespace std;
using namespace cv;
struct Bbox{
float xmin;
float ymin;
float xmax;
float ymax;
float score;
float x1;
float y1;
float x2;
float y2;
float x3;
float y3;
float x4;
float y4;
float x5;
float y5;
};
class RetinaFace{
public:
float confidence_threshold = 0.5;
bool is_bbox_process=true;
int num_thread = 2;
public:
bool model_init=false;
vector<int> input_size={640,640};
vector<float> variances={0.1,0.2};
float mean[3] = {104.0f, 117.0f, 123.0f};
float keep_top_k = 100;
float nms_threshold = 0.4;
float resize_scale = 1.0;
std::shared_ptr<MNN::Interpreter> net;
Session *session = nullptr;
MNN::Tensor* input_tensor=nullptr;
shared_ptr<MNN::CV::ImageProcess> pretreat;
vector<vector<float>> anchors;
private:
// 生成anchors
vector<vector<float>> priorBox(vector<int> image_size);
// 解析bounding box landmarks 包含置信度
vector<Bbox> decode(float *loc,float *score,float *pre,vector<vector<float>> priors,vector<float> variances);
// 解析landmarks
// vector<vector<float>> decode_landm(vector<vector<float>> pre,vector<vector<float>> priors,vector<float> variances);
//NMS
void nms_cpu(std::vector<Bbox> &bboxes, float threshold);
// 根据阈值筛选
vector<Bbox> select_score(vector<Bbox> bboxes,float threshold,float w_r,float h_r);
// 数据后处理
vector<Bbox> bbox_process(vector<Bbox> bboxes,float frame_w,float frame_h);
public:
RetinaFace();
// ~RetinaFace();
RetinaFace(string model_path){
init_model(model_path);
}
bool init_model(string model_path);
// 推理
vector<Bbox> detect(string image_path);
vector<Bbox> detect_image(Mat image);
};
#endif