python训练模型识别人脸性别及年龄代码

代码语言:python

所属分类:人工智能

代码描述:python训练模型识别人脸性别及年龄代码

代码标签: 识别 人脸 性别 年龄

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

#A Gender and Age Detection program by Mahesh Sawant

import cv2
import math
# import argparse

def highlightFace(net, frame, conf_threshold=0.7):
    frameOpencvDnn
=frame.copy()
    frameHeight
=frameOpencvDnn.shape[0]
    frameWidth
=frameOpencvDnn.shape[1]
    blob
=cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], True, False)

    net
.setInput(blob)
    detections
=net.forward()
    faceBoxes
=[]
   
for i in range(detections.shape[2]):
        confidence
=detections[0,0,i,2]
       
if confidence>conf_threshold:
            x1
=int(detections[0,0,i,3]*frameWidth)
            y1
=int(detections[0,0,i,4]*frameHeight)
            x2
=int(detections[0,0,i,5]*frameWidth)
            y2
=int(detections[0,0,i,6]*frameHeight)
            faceBoxes
.append([x1,y1,x2,y2])
            cv2
.rectangle(frameOpencvDnn, (x1,y1), (x2,y2), (0,255,0), int(round(frameHeight/150)), 8)
   
return frameOpencvDnn,faceBoxes


# parser=argparse.ArgumentParser()
# parser.add_argument('--image')

# args=parser.parse_args()

faceProto
="/data/wwwroot/default/model/opencv_face_.........完整代码请登录后点击上方下载按钮下载查看

网友评论0