facerecognize.h 1.6 KB
#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