update @ 202306 yunet/ libfacedetection
https://github.com/ShiqiYu/libfacedetection
据说比 haar还要快很多,待测试
经过初步测试, yunet同样的测试图片,比mlkit要快100%+
-----------------------------------------------------------------------------------------------------------------
update @ 202306
'com.google.mlkit:face-detection:16.1.5
在高通865 检测一张需要50ms,即20fps, 而同样环境,haar能达到30fps(受限于摄像头?)
No1:
protoPath = os.path.sep.join([args["detector"], "deploy.prototxt"])
modelPath = os.path.sep.join([args["detector"],"res10_300x300_ssd_iter_140000.caffemodel"])
net = cv2.dnn.readNetFromCaffe(protoPath, modelPath)
blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 1.0,(300, 300), (104.0, 177.0, 123.0))
net.setInput(blob)
detections = net.forward()
数度慢,但检测稳定性和准确率最高. gpu好的话可以把blob = cv2.dnn.blobFromImage(frame, 1.0, (600, 600),(104.0, 177.0, 123.0)),其中效果最好的是(900,900)
No2:
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
gray = cv2.cvtColor(frameClone_cascade, cv2.COLOR_BGR2GRAY)
rects = detector.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(20, 20),flags=cv2.CASCADE_SCALE_IMAGE)
优点1)几乎可以在CPU上实时工作;2)简单的架构;3)可以检测不同比例的人脸。缺点1)会出现大量的把非人脸预测为人脸的情况;2)不适用于非正面人脸图像;3)不抗遮挡。
存在的问题是人脸检测效果不好。正面/垂直/光线较好的人脸,该方法可以检测出来,而侧面/歪斜/光线不好的人脸,无法检测。因此,该方法不适合现场应用
No3:
detector_age_gender = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
rects = detector_age_gender(gray, 1)
dlib人脸检测方法采用64个特征点检测,效果会好于Haar的方法识别率会更高