电子人社区网讯:
这里的人脸识别准确的说是人脸比对,特征点比对。opencv是基于机器学习的,需要使用素材进行训练,不符合该系统的要求。所以这里使用dlib来实现。
从dlib官方网站http://dlib.net/下载源码,使用cmake生成visual stuido工程,然后编译。
编译dlib可能需要安装mkl,mkl下载地址:https://pan.baidu.com/s/1qYHriKs 密码:wl6z
使用dlib进行人脸图片比对的大致流程如下(代码摘要):
#include
#include
#include
#include
#include
#include
#include
template using residual = add_prev1;
template using residual_down = add_prev2;
template
using block = BN
template using ares_down => template using alevel0 = ares_down;
template using alevel1 = ares;
template using alevel2 = ares;
template using alevel3 = ares;
template using alevel4 = ares;
using anet_type = loss_metric>>>>>>>>>>;
// 声明anet_type
anet_type net;
// 使用dlib_face_recognition_resnet_model_v1.data初始化anet_type
//
QString strDataPath = QCoreApplication::applicationDirPath() + "/data/dlib_face_recognition_resnet_model_v1.dat";
try {
deserialize(cpp4j::Utf8ToAnsi(strDataPath.toStdString())) >> net;
}
catch (serialization_error &e) {
qDebug()
cv::resize(m_Face2, m_Face2,> cv::imwrite(strTmpFace1, m_Face1);
cv::imwrite(strTmpFace2, m_Face2);
matrix img1;
matrix img2;
load_image(img1, strTmpFace1);
load_image(img2, strTmpFace2);
std::vector> faces.push_back(img1);
faces.push_back(img2);
std::vector> // 比对结果是一个距离值
float f = length(face_descriptors[0] -> qDebug()
转载请注明:电子人社区 |