from mtcnn.mtcnn import MTCNN
import cv2
img=cv2.imread("C:/Users/xpp/Desktop/Lena.png")#读取图像
detector=MTCNN()
face_list=detector.detect_faces(img)#人脸检测与对齐
for face in face_list:
box=face["box"]
confidence=face["confidence"]
keypoints=face["keypoints"]
#边界框
x,y,w,h=box
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
#置信度
cv2.putText(img,str(round(confidence,4)),(x,y-10),0,0.5,(255,0,0))
#关键点
cv2.circle(img,keypoints["left_eye"],1,(0,0,255),2)
cv2.circle(img,keypoints["right_eye"],1,(0,0,255),2)
cv2.circle(img,keypoints["nose"],1,(0,0,255),2)
cv2.circle(img,keypoints["mouth_left"],1,(0,0,255),2)
cv2.circle(img,keypoints["mouth_right"],1,(0,0,255),2)
cv2.imwrite("C:/Users/xpp/Desktop/result.png",img)
算法:人脸检测是将人脸区域检测与人脸关键点检测放在了一起,它的主题框架类似于cascade。总体可分为P-Net、R-Net、和O-Net三层网络结构。
文献:Zhang, K. , Zhang, Z. , Li, Z. , & Qiao, Y. . (2016). Joint face detection and alignment using multitask cascaded convolutional networks. IEEE Signal Processing Letters, 23(10), 1499-1503.
链接:https://pypi.org/project/mtcnn/
本文分享自 图像处理与模式识别研究所 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!