facerecognize.h
1.6 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
#ifndef FACERECOGNIZE_H
#define FACERECOGNIZE_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;
class FaceRecognize{
public:
int num_thread = 2;
MNNForwardType forward_type = MNN_FORWARD_CPU;
// 推理
double inference(string image_path1,string image_path2);
double inference(Mat image1,Mat image2);
private:
vector<int> input_size={112,112};
bool model_init=false;
std::shared_ptr<MNN::Interpreter> net;
Session *session1 = nullptr;
Session *session2 = nullptr;
MNN::Tensor* input_tensor1=nullptr;
MNN::Tensor* input_tensor2=nullptr;
shared_ptr<MNN::CV::ImageProcess> pretreat;
float mean[3]={127.5f,127.5f,127.5f};
float normal[3] = {1.0f/127.5f,1.0f/127.5f,1.0f/127.5f};
public:
FaceRecognize();
// ~FaceRecognize();
FaceRecognize(string model_path){
init_model(model_path);
}
bool init_model(string model_path);
//预处理
cv::Mat meanAxis0(const cv::Mat &src);
cv::Mat elementwiseMinus(const cv::Mat &A,const cv::Mat &B);
cv::Mat varAxis0(const cv::Mat &src);
int MatrixRank(cv::Mat M);
cv::Mat similarTransform(cv::Mat src,cv::Mat dst);
Mat preprocess_face(Mat image,vector<vector<float>> land);
double getMold(const vector<double>& vec);
double cos_distance(const vector<double>& base, const vector<double>& target);
};
#endif