我一直在研究人脸识别考勤管理系统。我从头开始构建了管道,但最终,脚本在10个类中识别出了错误的面孔。我已经使用Tensorflow和Python实现了以下管道。
>
将图像Pickle成数据。pickle
文件,以便以后反序列化。
利用OpenCV实现MTCNN算法检测网络摄像头捕获的帧中的人脸
以下是运行步骤3和4的主文件:
from keras import backend as K
import time
from multiprocessing.dummy import Pool
K.set_image_data_format('channels_first')
import cv2
import os
import glob
import numpy as np
from numpy import genfromtxt
import tensorflow as tf
from keras.models import load_model
from fr_utils import *
from inception_blocks_v2 import *
from mtcnn.mtcnn import MTCNN
import dlib
from imutils import face_utils
import imutils
import pickle
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
FRmodel = load_model('face-rec_Google.h5')
# detector = dlib.get_frontal_face_detector()
detector = MTCNN()
# FRmodel = faceRecoModel(input_shape=(3, 96, 96))
#
# # detector = dlib.get_frontal_face_detector()
# # predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
# def triplet_loss(y_true, y_pred, alpha = 0.3):
# """
# Implementation of the triplet loss as defined by formula (3)
#
# Arguments:
# y_pred -- python list containing three objects:
# anchor -- the encodings for the anchor images, of shape (None, 128)
# positive -- the encodings for the positive images, of shape (None, 128)
# negative -- the encodings for the negative images, of shape (None, 128)
#
# Returns:
# loss -- real number, value of the loss
# """
#
# anchor, positive, negative = y_pred[0], y_pred[1], y_pred[2]
#
# pos_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, positive)), axis=-1)
# neg_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, negative)), axis=-1)
# basic_loss = tf.add(tf.subtract(pos_dist, neg_dist), alpha)
# loss = tf.reduce_sum(tf.maximum(basic_loss, 0.0))
#
# return loss
#
# FRmodel.compile(optimizer = 'adam', loss = triplet_loss, metrics = ['accuracy'])
# load_weights_from_FaceNet(FRmodel)
def ret_model():
return FRmodel
def prepare_database():
pickle_in = open("data.pickle","rb")
database = pickle.load(pickle_in)
return database
def unpickle_something(pickle_file):
pickle_in = open(pickle_file,"rb")
unpickled_file = pickle.load(pickle_in)
return unpickled_file
def webcam_face_recognizer(database):
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
while vc.isOpened():
ret, frame = vc.read()
img_rgb = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
img = frame
# We do not want to detect a new identity while the program is in the process of identifying another person
img = process_frame(img,img)
cv2.imshow("Preview", img)
cv2.waitKey(1)
vc.release()
def process_frame(img, frame):
"""
Determine whether the current frame contains the faces of people from our database
"""
# rects = detector(img)
rects = detector.detect_faces(img)
# Loop through all the faces detected and determine whether or not they are in the database
identities = []
for (i,rect) in enumerate(rects):
(x,y,w,h) = rect['box'][0],rect['box'][1],rect['box'][2],rect['box'][3]
img = cv2.rectangle(frame,(x, y),(x+w, y+h),(255,0,0),2)
identity = find_identity(frame, x-50, y-50, x+w+50, y+h+50)
cv2.putText(img, identity,(10,500), cv2.FONT_HERSHEY_SIMPLEX , 4,(255,255,255),2,cv2.LINE_AA)
if identity is not None:
identities.append(identity)
if identities != []:
cv2.imwrite('example.png',img)
return img
def find_identity(frame, x,y,w,h):
"""
Determine whether the face contained within the bounding box exists in our database
x1,y1_____________
| |
| |
|_________________x2,y2
"""
height, width, channels = frame.shape
# The padding is necessary since the OpenCV face detector creates the bounding box around the face and not the head
part_image = frame[y:y+h, x:x+w]
return who_is_it(part_image, database, FRmodel)
def who_is_it(image, database, model):
encoding = img_to_encoding(image, model)
min_dist = 100
# Loop over the database dictionary's names and encodings.
for (name, db_enc) in database.items():
# Compute L2 distance between the target "encoding" and the current "emb" from the database.
dist = np.linalg.norm(db_enc.flatten() - encoding.flatten())
print('distance for %s is %s' %(name, dist))
# If this distance is less than the min_dist, then set min_dist to dist, and identity to name
if dist < min_dist:
min_dist = dist
identity = name
if min_dist >0.1:
print('Unknown person')
else:
print(identity)
return identity
if __name__ == "__main__":
database = prepare_database()
webcam_face_recognizer(database)
我做错了什么?这里的FRM模型是经过facenet训练的模型
几点:
>
我没有看到输入面部图像的大小调整、对齐和美白。
不能向可变大小的面添加50的固定边距。必须进行缩放,使面部区域填充每个输入图像中几乎相同的区域。
我不确定您使用的模型,但如果您使用的是FaceNet,您接受的匹配阈值0.1似乎非常低。它将不接受任何匹配,除非它是相同的精确图像(距离为0.0),或者与库图像的差异非常小。
所以我和这个人有几乎完全一样的问题: Maven 安装 OSX 错误 不支持的主要.minor 版本 51.0 我认为问题出在我的符号链接中。我定义了$JAVA_HOME。bash_profile和java版本正确地报告了版本。然而,出于某种原因,mvn正在尝试使用旧版本的java。 这是我机器上所有东西的列表: 我想使用1.8。和mvn来识别它。 如果我运行这个: 然后如果我跑了: 我确实注意到
使用ML Kit的人脸识别API,您可以检测图像中的人脸并识别关键面部特征。 借助人脸识别功能,您可以获取所需的信息,以执行修饰自拍和美化人像等任务或从用户照片中生成头像。由于ML Kit可以执行实时的人脸识别,因此您可以将其用于视频聊天或会对玩家表情进行响应的游戏等应用程序。 iOS Android 核心功能 识别和定位面部特征 获取检测到的每个人脸的眼睛,耳朵,脸颊,鼻子和嘴巴的坐标。 识别面
1.1. 1.FACE SDK集成 1.2. 2. 接口说明及示例 1.2.1. 2.0 人脸检测参数配置: 1.2.2. 2.1 单帧图片检测: 1.2.3. 2.2 相机预览人脸检测: 1.2.4. 2.3 人脸数据库操作: Version:facelib.aar 1.1. 1.FACE SDK集成 添加三方依赖库: dependencies { compile 'com.rokid:
DWZ 百度人脸识别模块 dwzBaiduFaceLive 百度人脸识别模块【apicloud】 功能介绍 https://www.apicloud.com/mod_detail/dwzBaiduFaceLive 封装了新版百度开放平台的人脸识别采集 SDK: 包含活体动作 faceLiveness 不包含活体动作 faceDetect 考虑灵活度问题,本模块只作人脸采集,人脸识别成功后生成 ba
我能够找到这些面孔,并使用python将它们保存在本地目录中,然后根据下面视频中的代码打开cv 但是现在我想知道那个视频里有脸的人的身份...... 我如何定义此人的身份? 喜欢扫描人脸并将其匹配到本地人脸数据库中,如果找到匹配项,请给出姓名等
DWZ 百度人脸识别插件 dwz-BaiduFaceLive 百度人脸识别插件【dcloud】 功能介绍 https://ext.dcloud.net.cn/plugin?id=4794 封装了新版百度开放平台的人脸识别采集 SDK: 包含活体动作 faceLiveness 不包含活体动作 faceDetect 考虑灵活度问题,本插件只作人脸采集,人脸识别成功后生成 base64 头像图片,开发者