人脸检测
OpenCV在其深度学习例子程序里包含了人脸检测(Face Detection)和人脸识别(Face Recognition)的样例程序。人脸检测和物体识别类似,是利用谷歌的TensorFlow框架训练的深度学习网络,只是参数不同。
Model | Scale | Size WxH | Mean subtraction | Channels order |
---|---|---|---|---|
MobileNet-SSD, Caffe | 0.00784 (2/255) |
300x300 |
127.5 127.5 127.5 |
BGR |
OpenCV face detector | 1.0 |
300x300 |
104 177 123 |
BGR |
现在master分支只有模型和一个网页demo:
- face_detector
- js_face_recognition.html
网页demo里包含了需要的深度学习模型信息:
var proto = 'https://raw.githubusercontent.com/opencv/opencv/master/samples/dnn/face_detector/deploy.prototxt';
var weights = 'https://raw.githubusercontent.com/opencv/opencv_3rdparty/dnn_samples_face_detector_20180205_fp16/res10_300x300_ssd_iter_140000_fp16.caffemodel';
var recognModel = 'https://raw.githubusercontent.com/pyannote/pyannote-data/master/openface.nn4.small2.v1.t7';
流程是先进行人脸检测,再对检测出来的部分做人脸识别。
人脸检测用ResNet SSD网络,人脸识别用OpenFace的网络模型。
原来的cpp程序在另外一个分支上面:
- face_detector
- resnet_ssd_face.cpp
Openface人脸识别
dnn::Net net = dnn::readNetFromTorch("openface.nn4.small2.v1.t7");
Mat recognize(Mat face) {
Mat inputBlob = dnn::blobFromImage(face, 1./255, Size(96,96), Scalar(), true, false);
net.setInput(inputBlob);
Mat feature = net.forward().clone();
return feature;
}
得到的feature是一个128维的特征向量。
链接
opencv dnn samples
Face detection with OpenCV and deep learning
openface