基于开源face_recognition库做的人脸检测,调用的情绪识别模型由VGG训练保存的模型
只是简单的功能实现,速度有待提高
import face_recognition
import cv2
import numpy as np
from keras.models import load_model
def img_face_dectect(img):
# img = face_recognition.load_image_file(img)
face_locations = face_recognition.face_locations(img)
# print(type(face_locations))
# print(face_locations)
# cv2.imshow(face_locations)
for (top, right, bottom, left) in face_locations:
# top *= 4
# right *= 4
# bottom *= 4
# left *= 4
# print(left,top,right,bottom)
cv2.rectangle(img, (left, top), (right, bottom), (0, 0, 255), 2)
return img
def cap_face_dectect():
cap = cv2.VideoCapture(0)
while (True):
ret, frame = cap.read()
if ret == True:
# known_image = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
img