资源简介
利用opencv进行人脸识别,包括人脸检测+特征提取 最常见的人脸识别方法采用的是:人脸检测+人脸对齐+特征提取+识别,本文方法没有采用人脸对齐,因为本来opencv提取的特征效果就不好,只是参考玩玩。
代码片段和文件信息
#include “FaceDetect.h“
void read_csv(const string& filename cv::vector& images cv::vector& labels char separator = ‘;‘) {
std::ifstream file(filename.c_str() ifstream::in);
if (!file) {
string error_message = “No valid input file was given please check the given filename.“;
CV_Error(CV_StsBadArg error_message);
}
string line path classlabel;
while (getline(file line)) {
stringstream liness(line);
getline(liness path separator);
getline(liness classlabel);
if (!path.empty() && !classlabel.empty()) {
Mat image = imread(path 1);
Mat face = FaceDetect(image);
/*Mat facegray;
cvtColor(face facegray CV_BGR2GRAY);*/
images.push_back(face);
labels.push_back(atoi(classlabel.c_str()));
}
}
}
cv::Mat FaceToOne(cv::Mat source)//归一化处理函数
{
cv::equalizeHist(source source);//直方图均衡
cv::resize(source source cv::Size(92 112));//裁剪
cv::Mat Mask = cv::imread(“mask.jpg“ 0);
cv::Mat changedMask;
source.copyTo(changedMask Mask);
return changedMask;
}
Mat FaceDetect(Mat& frame)//脸是否存在
{
Mat gray error;
cvtColor(frame gray CV_BGR2GRAY);
int * pResults = NULL;
pResults = facedetect_frontal((unsigned char*)(gray.ptr(0)) gray.data gray.cols gray.rows gray.step
1.2f 5 24);
//pResults = facedetect_frontal_tmp((unsigned char*)(gray.ptr(0)) gray.cols gray.rows gray.step 1.2f 5 24);
int peopleNUM = (pResults ? *pResults : 0);
float Area = 0.0f;
Rect MaxRect(0000);
for (int i = 0; i < peopleNUM; i++)//代表有几张人脸(pResults ? *pResults : 0)
{
short * p = ((short*)(pResults + 1)) + 6 * i;
float area = p[2] * p[3];
if(area > Area)
{
Area = area;
Rect opencvRect(p[0] p[1] p[2] p[3]);
MaxRect = opencvRect;
}
}
if (0 != MaxRect.area())
{
cv::rectangle(frame MaxRect Scalar(255 0 0) 2);
Mat pic = gray(MaxRect);//感觉加了mask以后效果并不好
Mat pic_resize;
cv::resize(pic pic_resize cv::Size(100 100));
/*cvtColor(pic pic CV_BGR2GRAY);
return FaceToOne(pic);*/
return pic_resize;
}
else
return error;
}
Ptr GetTrainModel(string fn_csv)//输入CSV文件的路径名
{
vector images;
vector labels;
try {
read_csv(fn_csv images labels);
}
catch (cv::Exception& e) {
cerr << “Error opening file \““ << fn_csv << “\“. Reason: “ << e.msg << endl;
// 文件有问题,我们啥也做不了了,退出了
exit(1);
}
// 如果没有读取到足够图片,我们也得退出.
if (images.size() <= 1) {
string error_message = “This demo needs at least 2 images to work. Please add more images to your data set!“;
CV_Error(CV_StsError error_message);
}
Ptr model = createLBPHFaceRecognizer();//创建人脸识别类 可修改 LBPHFace、EigenFace、FisherFace
model->train(images labels);
return model;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-12 16:37 FaceRecognition_Opencv\
目录 0 2017-10-12 15:08 FaceRecognition_Opencv\.vs\
目录 0 2017-10-12 15:08 FaceRecognition_Opencv\.vs\FaceRecognition_Opencv\
目录 0 2017-10-12 15:08 FaceRecognition_Opencv\.vs\FaceRecognition_Opencv\v14\
文件 26112 2017-10-12 16:37 FaceRecognition_Opencv\.vs\FaceRecognition_Opencv\v14\.suo
目录 0 2017-10-12 16:38 FaceRecognition_Opencv\FaceRecognition_Opencv\
文件 2877 2017-10-12 16:25 FaceRecognition_Opencv\FaceRecognition_Opencv\FaceDetect.cpp
文件 242 2017-10-12 16:32 FaceRecognition_Opencv\FaceRecognition_Opencv\FaceDetect.h
文件 845 2017-10-12 16:23 FaceRecognition_Opencv\FaceRecognition_Opencv\FaceRecognition.cpp
文件 8905 2017-10-12 16:09 FaceRecognition_Opencv\FaceRecognition_Opencv\FaceRecognition_Opencv.vcxproj
文件 1173 2017-10-12 15:55 FaceRecognition_Opencv\FaceRecognition_Opencv\FaceRecognition_Opencv.vcxproj.filters
文件 165 2017-10-12 15:08 FaceRecognition_Opencv\FaceRecognition_Opencv\FaceRecognition_Opencv.vcxproj.user
文件 68 2017-10-12 16:17 FaceRecognition_Opencv\FaceRecognition_Opencv\face.csv
文件 9933312 2017-04-14 09:13 FaceRecognition_Opencv\FaceRecognition_Opencv\libfacedetect-x64.dll
文件 17297 2017-09-14 15:18 FaceRecognition_Opencv\FaceRecognition_Opencv\mask.jpg
目录 0 2017-10-12 16:08 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\
目录 0 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\
文件 814234 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceDetect.obj
目录 0 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\
文件 1430 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\CL.command.1.tlog
文件 33240 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\CL.read.1.tlog
文件 2286 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\CL.write.1.tlog
文件 208 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\FaceRecognition_Opencv.lastbuildstate
文件 2490 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\li
文件 5490 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\li
文件 796 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceReco.D22FE948.tlog\li
文件 302873 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceRecognition.obj
文件 706 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\FaceRecognition_Opencv.log
文件 912384 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\vc140.idb
文件 1601536 2017-10-12 16:34 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Debug\vc140.pdb
目录 0 2017-10-12 16:00 FaceRecognition_Opencv\FaceRecognition_Opencv\x64\Release\
............此处省略44个文件信息
- 上一篇:最新mingw5.1.6
- 下一篇:Node.js开发实战详解源代码
相关资源
- LearningOpenCV3ComputervisioninC.pdf
- 人脸识别.rar
- OpenCV 3和Qt5计算机视觉应用开发英文版
- 海康工业相机二次开发源码 + OpenCV3
- 人脸自动分割.
- Opencv3.4SUFR纵向图像平滑拼接
- OpenCV Linux依赖库ippicv_linux_20151201.tgz
- 刷脸背后 人脸检测 人脸识别 人脸检
- 毕设-人脸识别技术
- 使用OpenCV 手势识别
- win32平台的opencv3.3.0
- OpenCV-2.1.0-win32-vs2008
- OpenCV3编程入门_毛星云编著_电子工业
-
Extend Yale B Databa
se 人脸识别 - 基于百度API的使用js实现的人脸识别
- OpenCV2.3.1库已编译完成,可以直接添加
- opencv2.2.0-win.zip
- OpenCV LBP特征提取源代码
- OpenCV实现SfM:双目三维重建
-
Extend Yale B databa
se - IMM人脸数据库
- opencv相机标定程序
- 基于opencv的图片旋转实现
- QT+OpenCV+VS Gerber光绘文件识别
- 海康威视实时视频预览+opencv实时处理
- 计盒维数/盒维数OpenCV计算图片分形维
- 《OpenCV教程》电子书+源代码
- 人脸识别 测试头像 800张图片
-
opencv2.fr
amework - 基于opencv的二维码畸变矫正QT程序
评论
共有 条评论