在上一篇使用python实现情绪识别的基础上,使用c++实现情绪识别。
这里的人脸检测模块不是使用dlib模块(使用dlib模块也可以,测试以后发现速度比较慢),这里使用另外一个开源的模块。
facedetect-dll.h,可以去我的资源里下载。里面的眉毛斜率检测模块,因为c++没有np.polyfit,所以需要自己实现(参考最小二乘)。
#include <fstream>
#include <string>
#include <iostream>
//#include <dlib/image_processing/frontal_face_detector.h>
//#include <dlib/image_processing/render_face_detections.h>
//#include <dlib/image_processing.h>
//#include <dlib/gui_widgets.h>
//#include <dlib/image_io.h>
#include <opencv2/core/core.hpp>
//#include <dlib/timer.h>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include "highgui.h"
#include "lib\facedetect-dll.h"
#include <iostream>
#include <cstdlib>
#include "lib\facedetect-dll.h"
using namespace cv;
using namespace std;
using namespace dnn;
float LineFitLeastSquares(float *data_x, float *data_y, int data_n);
// ----------------------------------------------------------------------------------------
//
#define DETECT_BUFFER_SIZE 0x20000
int main()
{
const char* path = "E:/fangtu1/1/FTA001190217537664_一寸照.jpg";
unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
//auto src = cv::imread("C:/Users/01/Desktop/face/CNN_Face_Glass_Classfy-master/face7.jpg");
auto src = cv::imread(path);
Mat gray;
cvtColor(src, gray, CV_BGR2GRAY);
auto pResults = facedetect_multiview_reinforce(pBuffer, (un