-
Notifications
You must be signed in to change notification settings - Fork 2
/
ultraface.h
82 lines (62 loc) · 2.04 KB
/
ultraface.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
#ifndef UltraFace_hpp
#define UltraFace_hpp
#pragma once
#include <MNN/Interpreter.hpp>
#include <MNN/MNNDefine.h>
#include <MNN/Tensor.hpp>
#include <MNN/ImageProcess.hpp>
#include <opencv2/opencv.hpp>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <chrono>
#define num_featuremap 4
#define hard_nms 1
#define blending_nms 2 /* mix nms was been proposaled in paper blaze face, aims to minimize the temporal jitter*/
typedef struct FaceInfo {
float x1;
float y1;
float x2;
float y2;
float score;
} FaceInfo;
class UltraFace {
public:
UltraFace(const std::string& mnn_path,
int input_width, int input_length, int num_thread_ = 4, float score_threshold_ = 0.7, float iou_threshold_ = 0.3,
int topk_ = -1);
~UltraFace();
int detect(cv::Mat& img, std::vector<FaceInfo>& face_list);
private:
void generateBBox(std::vector<FaceInfo>& bbox_collection, MNN::Tensor* scores, MNN::Tensor* boxes);
void nms(std::vector<FaceInfo>& input, std::vector<FaceInfo>& output, int type = blending_nms);
private:
std::shared_ptr<MNN::Interpreter> ultraface_interpreter;
MNN::Session* ultraface_session = nullptr;
MNN::Tensor* input_tensor = nullptr;
int num_thread;
int image_w;
int image_h;
int in_w;
int in_h;
int num_anchors;
float score_threshold;
float iou_threshold;
const float mean_vals[3] = { 127, 127, 127 };
const float norm_vals[3] = { 1.0 / 128, 1.0 / 128, 1.0 / 128 };
const float center_variance = 0.1;
const float size_variance = 0.2;
const std::vector<std::vector<float>> min_boxes = {
{10.0f, 16.0f, 24.0f},
{32.0f, 48.0f},
{64.0f, 96.0f},
{128.0f, 192.0f, 256.0f} };
const std::vector<float> strides = { 8.0, 16.0, 32.0, 64.0 };
std::vector<std::vector<float>> featuremap_size;
std::vector<std::vector<float>> shrinkage_size;
std::vector<int> w_h_list;
std::vector<std::vector<float>> priors = {};
};
#endif /* UltraFace_hpp */