OpenCV人脸识别三(根据训练的模型进行人脸识别)
OpenCV版本3.4.1
人脸识别算法采用:LBPHFaceRecognizer
.pro文件代码
QT += core
QT -= gui
CONFIG += c++11
TARGET = opencvTest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
fisherdemo.cpp \
lbphdemo.cpp \
lbphdemo2.cpp \
lbphdemo3.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += G:/OpenCV/opencv/sources-build/install/include/opencv \
G:/OpenCV/opencv/sources-build/install/include/opencv2 \
G:/OpenCV/opencv/sources-build/install/include
LIBS +=-LG:/OpenCV/opencv/sources-build/install/x86/mingw/lib/ \
-llibopencv_core341 \
-llibopencv_highgui341 \
-llibopencv_imgcodecs341 \
-llibopencv_imgproc341 \
-llibopencv_face341 \
-llibopencv_features2d341 \
-llibopencv_calib3d341
main.cpp代码
#include <QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/face.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace face;
using namespace std;
/**LBPHFaceRecognizer根据训练模型预测结果
* @brief main
* @param argc
* @param argv
* @return
*/
int main(int argc,char *argv[])
{
QCoreApplication a(argc,argv);
Mat src_5=imread("G:/opencvImage/att_faces/s3/1.pgm",CV_LOAD_IMAGE_GRAYSCALE);
Ptr<FaceRecognizer> model=LBPHFaceRecognizer::create();
model->read("G:/opencvImage/lbph_face.xml");
int faceResult=model->predict(src_5);
cout << faceResult << endl;
return a.exec();
}
还没有评论,来说两句吧...