#include "face_model.h"
#include<QDebug>
#include<QString>
#include<QFile>
#include<QMessageBox>
#include<QCoreApplication>
void Person::set_cn_name(QString name)
{
name_cn = name;
}
void Person::set_eng_name(QString name)
{
name_eng = name;
}
void Person::set_idnum(QString name)
{
id_num = name;
}
void Person::set_face_feature(dlib::matrix<float,0,1> features)
{
face_feature = features;
}
FaceDetector::FaceDetector()
{
QString exe_path = QCoreApplication::applicationDirPath();
xml_path = exe_path +"/data/haarcascade_frontalface_alt2.xml";
face_landmarks_path = exe_path + "/data/shape_predictor_68_face_landmarks.dat";
resnet_model_path = exe_path + "/data/dlib_face_recognition_resnet_model_v1.dat";
pic_dir_path = exe_path + "/data/face_info.txt";
dir_path = exe_path + "/data/face_lib";
add_face_batch(pic_dir_path);
}
bool FaceDetector::add_face(Person person)
{
qDebug()<<person.name_cn;
qDebug()<<person.name_eng;
qDebug()<<person.pic_path;
// qDebug()<< strList[0]<<strList[1]<<strList[2]<<strList[3];
QString write_txt = person.name_cn + " " +
person.name_eng + " " +
person.id_num + " " + //person.class_num + " " +
person.pic_path.split("/")[person.pic_path.split("/").size()-1] + " ";
QFile file(pic_dir_path);
if (file.open(QIODevice::ReadWrite | QIODevice::Text))
{
QTextStream stream(&file);
stream.seek(file.size());
stream <<"\n"<<write_txt;
file.close();
}
// 构建人脸库信息
Person *person_temp = new Person;
person_temp->set_cn_name(person.name_cn);
person_temp->set_eng_name(person.name_eng);
person_temp->set_idnum(person.id_num);
person_temp->class_num = person.class_num;
cv::Mat src;
cv::Mat frame = cv::imread(person.pic_path.toStdString());
cv::cvtColor(frame, src, cv::COLOR_BGR2GRAY);
dlib::array2d<dlib::bgr_pixel> dimg;
dlib::assign_image(dimg, dlib::cv_image<uchar>(src));
//haar级联分类器探测人脸区域,获取一系列人脸所在区域
std::vector<cv::Rect> objects;
std::vector<dlib::rectangle> dets;
face_detector.detectMultiScale(src, objects);
for (int i = 0; i < objects.size(); i++)
{
// cv::rectangle(frame, objects[i], CV_RGB(200,0,0));
dlib::rectangle r(objects[i].x, objects[i].y, objects[i].x + objects[i].width, objects[i].y + objects[i].height);
if(r.area()>10000)
dets.push_back(r); //正常情况下应该只检测到一副面容
}
// if (dets.size() == 0)
// continue;
std::vector<dlib::matrix<dlib::rgb_pixel>> faces;
std::vector<dlib::full_object_detection> shapes;
for(int i = 0; i < dets.size(); i++)
{
dlib::full_object_detection shape = sp(dimg, dets[i]); //获取指定一个区域的人脸形状
shapes.push_back(shape);
dlib::matrix<dlib::rgb_pixel> face_chip;
dlib::extract_image_chip(dimg, dlib::get_face_chip_details(shape,150,0.25), face_chip);
faces.push_back(std::move(face_chip));
}
if (faces.size() == 0)
{
// qDebug()<< "No faces found in " <<person_temp->name_eng<<endl;
;// continue;
}
std::vector<dlib::matrix<float,0,1>> face_descriptors = net(faces);
//qDebug()<<face_descriptors.size();
person_temp->set_face_feature(face_descriptors[0]);
fdlib.push_back(*person_temp);
}
bool FaceDetector::add_face_batch(QString pic_dir_path)
{
face_detector.load(xml_path.toStdString());
dlib::deserialize(face_landmarks_path.toStdString()) >> sp;
dlib::deserialize(resnet_model_path.toStdString()) >> net;
QFile file(pic_dir_path);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
//qDebug()<<"Can't open the file!"<<endl;
}
while(!file.atEnd())
{
QByteArray line = file.readLine();
QString str(line);
QStringList strList = str.split(" ");
qDebug()<< strList[0]<<strList[1]<<strList[2]<<strList[3];
// 构建人脸库信息
Person *person_temp = new Person;
person_temp->set_cn_name(strList[0]);
person_temp->set_eng_name(strList[1]);
person_temp->set_idnum(strList[2]);
//qDebug()<<person_temp->name_cn<<person_temp->name_eng<<person_temp->id_num;
cv::Mat src;
std::string path= strList[3].toStdString();
//qDebug()<<"PATH:"<<strList[3];
QString qstr2 = QString::fromStdString(path);
//qDebug()<<dir_path + qstr2;
cv::Mat frame = cv::imread(dir_path.toStdString()+"/"+path);
cv::cvtColor(frame, src, cv::COLOR_BGR2GRAY);
// cv::imshow("1",src);
// cv::waitKey(2000);
dlib::array2d<dlib::bgr_pixel> dimg;
dlib::assign_image(dimg, dlib::cv_image<uchar>(src));
//haar级联分类器探测人脸区域,获取一系列人脸所在区域
std::vector<cv::Rect> objects;
std::vector<dlib::rectangle> dets;
face_detector.detectMultiScale(src, objects);
for (int i = 0; i < objects.size(); i++)
{
// cv::rectangle(frame, objects[i], CV_RGB(200,0,0));
dlib::rectangle r(objects[i].x, objects[i].y, objects[i].x + objects[i].width, objects[i].y + objects[i].height);
if(r.area()>10000)
dets.push_back(r); //正常情况下应该只检测到一副面容
}
if (dets.size() == 0)
continue;
std::vector<dlib::matrix<dlib::rgb_pixel>> faces;
std::vector<dlib::full_object_detection> shapes;
for(int i = 0; i < dets.size(); i++)
{
dlib::full_object_detection shape = sp(dimg, dets[i]); //获取指定一个区域的人脸形状
shapes.push_back(shape);
dlib::matrix<dlib::rgb_pixel> face_chip;
dlib::extract_image_chip(dimg, dlib::get_face_chip_details(shape,150,0.25), face_chip);
faces.push_back(std::move(face_chip));
}
if (faces.size() == 0)
{
// qDebug()<< "No faces found in " <<person_temp->name_eng<<endl;
continue;
}
std::vector<dlib::matrix<float,0,1>> face_descriptors = net(faces);
//qDebug()<<face_descriptors.size();
person_temp->set_face_feature(face_descriptors[0]);
fdlib.push_back(*person_temp);
}
}
bool FaceDetector::recog_face(cv::Mat &img,Person &person)
{
cv::Mat src_test;
cv::cvtColor(img, src_test, cv::COLOR_BGR2GRAY);
dlib::array2d<dlib::bgr_pixel> dimg;
dlib::assign_image(dimg, dlib::cv_image<uchar>(src_test));
//haar级联分类器探测人脸区域,获取一系列人脸所在区域
std::vector<cv::Rect> objects;
std::vector<cv::Rect> objects_temp;
std::vector<dlib::rectangle> dets;
face_detector.detectMultiScale(src_test, objects_temp);
for(int i = 0;i < objects_temp.size();i++)
{
if(objects_temp[i].area()<10000)
{
continue;
}
objects.push_back(objects_temp[i]);
}
for (int i = 0; i < objects.size(); i++)
{
dlib::rectangle r(objects[i].x, objects[i].y, objects[i].x + objects[i].width, objects[i].y + objects[i].height);
if(r.area()<10000)
{
continue;
}
cv::rectangle(img, objects[i], CV_RGB(200,0,0));
dets.push_back(r); //正常情况下应该只检测到一副面容
}
if (dets.size() == 0)
{
//qDebug()<< "there is no faces found in "<<endl;
return false;
}
std::vector<dlib::matrix<dlib::rgb_pixel>> faces;
std::vector<dlib::full_object_detection> shapes;
for(int i = 0; i < dets.size(); i++)
{
dlib::full_object_detection shape =
没有合适的资源?快使用搜索试试~ 我知道了~
C++人脸识别签到考勤系统源码(优质毕业设计项目).zip
共23个文件
cpp:6个
h:6个
ui:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 165 浏览量
2024-04-22
21:05:14
上传
评论
收藏 89.06MB ZIP 举报
温馨提示
C++人脸识别签到考勤系统源码(优质毕业设计项目).zip人脸识别签到考勤系统 使用 opencv 4.2 dlib库 ,qt, 使用opencv的dnn模块实现人脸位置的检测。使用dlib库重新训练人脸特征器,获取人脸特征点以及特征向量进行人脸识别、最后利用上位机显示。 C++人脸识别签到考勤系统源码(优质毕业设计项目).zip人脸识别签到考勤系统 使用 opencv 4.2 dlib库 ,qt, 使用opencv的dnn模块实现人脸位置的检测。使用dlib库重新训练人脸特征器,获取人脸特征点以及特征向量进行人脸识别、最后利用上位机显示。 C++人脸识别签到考勤系统源码(优质毕业设计项目).zip人脸识别签到考勤系统 使用 opencv 4.2 dlib库 ,qt, 使用opencv的dnn模块实现人脸位置的检测。使用dlib库重新训练人脸特征器,获取人脸特征点以及特征向量进行人脸识别、最后利用上位机显示。 C++人脸识别签到考勤系统源码(优质毕业设计项目).zip人脸识别签到考勤系统 使用 opencv 4.2 dlib库 ,qt, 使用opencv的dnn模块实现人脸位置
资源推荐
资源详情
资源评论
收起资源包目录
C++人脸识别签到考勤系统源码.zip (23个子文件)
face_signin-master
widget.ui 3KB
administor.h 664B
widget.cpp 2KB
shape_predictor_68_face_landmarks.dat 95.08MB
dialog.ui 5KB
dialog.cpp 2KB
admin.h 461B
main.cpp 325B
.gitee
ISSUE_TEMPLATE.zh-CN.md 79B
form.ui 378B
admin.ui 5KB
administor.cpp 3KB
face_model.cpp 11KB
form.cpp 5KB
form.h 1009B
face_signin.pro.user 24KB
dlib_face_recognition_resnet_model_v1.dat 21.43MB
administor.ui 8KB
haarcascade_frontalface_alt2.xml 528KB
dialog.h 484B
face_model.h 4KB
face_signin.pro 1KB
widget.h 1KB
共 23 条
- 1
资源评论
程序员张小妍
- 粉丝: 1w+
- 资源: 3027
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功