前期的文章我们分享了人脸的识别以及如何进行人脸数据的训练,本期文章我们结合人脸识别的
模型进行人脸性别的检测
人脸性别的检测步骤
1、首先需要进行人脸的检测
2、把检测到的人脸数据给性别检测模型去检测
3、把检测结果呈现到图片上
import numpy as np
import cv2import osgenderList = ['Male', 'Female']
prototxtFacePath = "model/deploy.prototxt"
weightsFacePath = "model/res10_300x300_ssd_iter_140000.caffemodel"
faceNet = cv2.dnn.readNet(prototxtFacePath, weightsFacePath)prototxtGenderPath = "model/deploy_gender.prototxt"
weightsGenderPath = "model/gender_net.caffemodel"
genderNet = cv2.dnn.readNet(prototxtGenderPath, weightsGenderPath)
初始化模型性别,当然你也可以使用大量的数据,进行更准确的模型训练
然后cv2.dnn.readNet加载人脸识别的模型,可参考往期文章
最后cv2.dnn.readNet加载人脸年龄的模型
image = cv2