-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathmtcnn.h
64 lines (56 loc) · 1.74 KB
/
mtcnn.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
#ifndef __MTCNN_NCNN_H__
#define __MTCNN_NCNN_H__
#include "ncnn/net.h"
#include <string>
#include <vector>
#include <time.h>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
struct Bbox
{
float score;
int x1;
int y1;
int x2;
int y2;
float area;
float ppoint[10];
float regreCoord[4];
};
class MTCNN {
public:
bool init(const string &model_path);
MTCNN() {};
~MTCNN();
void SetMinFace(int minSize);
void detect(ncnn::Mat& img_, std::vector<Bbox>& finalBbox);
void detectMaxFace(ncnn::Mat& img_, std::vector<Bbox>& finalBbox);
private:
void generateBbox(ncnn::Mat score, ncnn::Mat location, vector<Bbox>& boundingBox_, float scale);
void nmsTwoBoxs(vector<Bbox> &boundingBox_, vector<Bbox> &previousBox_, const float overlap_threshold, string modelname = "Union");
void nms(vector<Bbox> &boundingBox_, const float overlap_threshold, string modelname="Union");
void refine(vector<Bbox> &vecBbox, const int &height, const int &width, bool square);
void extractMaxFace(vector<Bbox> &boundingBox_);
void PNet(float scale);
void PNet();
void RNet();
void ONet();
void release();
ncnn::Net Pnet, Rnet, Onet;
ncnn::Mat img;
const float nms_threshold[3] = {0.5f, 0.7f, 0.7f};
const float mean_vals[3] = {127.5f, 127.5f, 127.5f};
const float norm_vals[3] = {0.0078125f, 0.0078125f, 0.0078125f};
const int MIN_DET_SIZE = 12;
std::vector<Bbox> firstPreviousBbox_, secondPreviousBbox_, thirdPrevioussBbox_;
std::vector<Bbox> firstBbox_, secondBbox_,thirdBbox_;
int img_w, img_h;
private:
const float threshold[3] = { 0.8f, 0.8f, 0.6f };
int minsize = 40;
const float pre_facetor = 0.709f;
bool binited = false;
};
#endif //__MTCNN_NCNN_H__