该测试文件需要放置在FaceIdentification/src/test目录下,为方便编译,代码预处理部分跟文件夹中test_face_verification.cpp相同。编译该文件之前,需要先完成facedetection,facealignment,faceidentification三个模块的编译。
代码如下:
#include<iostream>
using namespace std;
#ifdef _WIN32
#pragma once
#include <opencv2/core/version.hpp>
#define CV_VERSION_ID CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) \
CVAUX_STR(CV_SUBMINOR_VERSION)
#ifdef _DEBUG
#define cvLIB(name) "opencv_" name CV_VERSION_ID "d"
#else
#define cvLIB(name) "opencv_" name CV_VERSION_ID
#endif //_DEBUG
#pragma comment( lib, cvLIB("core") )
#pragma comment( lib, cvLIB("imgproc") )
#pragma comment( lib, cvLIB("highgui") )
#endif //_WIN32
#if defined(__unix__) || defined(__APPLE__)
#ifndef fopen_s
#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename),(mode)))==NULL
#endif //fopen_s
#endif //__unix
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include "face_identification.h"
#include "recognizer.h"
#include "face_detection.h"
#include "face_alignment.h"
#include <dirent.h>
#include "math_functions.h"
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <thread>
#include <mutex>
using namespace seeta;
#define TEST(major, minor) major##_##minor##_Tester()
#define EXPECT_NE(a, b) if ((a) == (b)) std::cout << "ERROR: "
#define EXPECT_EQ(a, b) if ((a) != (b)) std::cout << "ERROR: "
//声明变量==============================================================================
cv::Mat frame;
std::vector<std::string> file_name;
float temp_fea[2048];
std::mutex mtx;
bool get_face=false;
struct st_a{
std::string name;
float fea[2048];
float sim;
};
struct st_b{
std::string name;
float sim;
};
st_a * fea;
//声明函数=============================================================================
void extract_from_file(std::vector<seeta::FaceInfo> &,int n );
std::vector<std::string> read_name_from_file(const char* filepath);
void extract_from_cam(seeta::FaceDetection & ,seeta::FaceAlignment & ,FaceIdentification & ,std::vector<seeta::FaceInfo> & );
void show_video(cv::VideoCapture & cap);
void show_picture(std::string filename,std::string win_name,int h_position,int v_position);
//main main main==============================================================================================
int main(){
const char* filepath = "/home/wd/seeta/image_storehouse";
const char* image_path =