系统发现类似面孔时突然关闭

时间:2019-10-03 04:30:42

标签: python face-recognition

我正在做我的第一个人脸识别项目

我有将被编码的面部图像数据,所以这是我的目录

./Desktop/dataset/amber_heard/image.jpg
./Desktop/dataset/jokowi/image.jpg

这是我的代码:

import face_recognition
import cv2
import numpy as np
import os
import glob

video_capture = cv2.VideoCapture(0)
known_face_encodings = []
known_face_names = []

os.chdir("./dataset")
for file in glob.glob("**/*.jpg"):

    images = face_recognition.load_image_file(file)
    images_encoding = face_recognition.face_encodings(images)[0]
    known_face_encodings.append(images_encoding)
    print(images_encoding)

    dir_list = next(os.walk('.'))[1]
    known_face_names.append(dir_list)

我正在使用link中的代码,我只是将比较代码更改为:

        face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)     
        best_match_index = np.argmin(face_distances)
        if matches[best_match_index] and matches[best_match_index] < 0.3:
            name = known_face_names[best_match_index]

        face_names.append(name)

process_this_frame = not process_this_frame

我使用os.walk()从目录dataset获取我的子目录,如果系统从我的数据集中检测到相似的面孔,则系统将根据我的子目录名称显示该名称。

但是我的问题是,当我的网络摄像头检测到相似的面孔时。我的系统突然关闭。我的代码有什么问题吗?我真的需要解决方案。提前致谢 !请原谅我的英语。

0 个答案:

没有答案