facerecognize.h
1.49 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
#ifndef FACERECOGNIZE_H
#define FACERECOGNIZE_H
#include<opencv2/opencv.hpp>
#include<MNN/Interpreter.hpp>
#include<MNN/ImageProcess.hpp>
#include<iostream>
using namespace MNN;
using namespace std;
using namespace cv;
class FaceRecognize{
private:
vector<float> input_size={112,112};
std::shared_ptr<MNN::Interpreter> net;
Session *session1 = nullptr;
Session *session2 = nullptr;
ScheduleConfig config;
Scalar mean=Scalar(127.5f,127.5f,127.5f);
float scale = 1.0f/127.5f;
public:
FaceRecognize(){};
FaceRecognize(string model_path){
net = std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(model_path.c_str()));//创建解释器
config.numThread = 8;
config.type = MNN_FORWARD_CPU;
session1 = net->createSession(config);//创建session
session2 = net->createSession(config);//创建session
}
//预处理
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);
// 推理
double get_samilar(Mat image1,Mat image2);
};
#endif