首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么face_recognition模块在Python语言中不能工作?

为什么face_recognition模块在Python语言中不能工作?
EN

Stack Overflow用户
提问于 2020-12-05 13:32:37
回答 1查看 533关注 0票数 0

我正在用Python编写一个人脸识别脚本。我正在使用Python语言中的face_recognition模块。但是当我运行代码时,我得到的输出是:

代码语言:javascript
复制
Please install `face_recognition_models` with this command before using `face_recognition`:

pip install git+https://github.com/ageitgey/face_recognition_models

Process finished with exit code 0

我运行了它建议的命令,并且我还安装了'face_recognition_models‘。但是它仍然要求我安装这个模块。你能帮帮忙吗?

这是我的代码:

代码语言:javascript
复制
import numpy as np
import face_recognition as fr
import cv2

video_capture = cv2.VideoCapture(0)

my_image = fr.load_image_file("face.jpg")
my_face_encoding = fr.face_encodings(bruno_image)[0]

known_face_encondings = [my_face_encoding]
known_face_names = ["Adrian"]

while True:
    ret, frame = video_capture.read()

    rgb_frame = frame[:, :, ::-1]

    face_locations = fr.face_locations(rgb_frame)
    face_encodings = fr.face_encodings(rgb_frame, face_locations)

    for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):

        matches = fr.compare_faces(known_face_encondings, face_encoding)

        name = "Unknown"

        face_distances = fr.face_distance(known_face_encondings, face_encoding)

        best_match_index = np.argmin(face_distances)
        if matches[best_match_index]:
            name = known_face_names[best_match_index]

        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

        cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)

    cv2.imshow('Webcam_facerecognition', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()
EN

回答 1

Stack Overflow用户

发布于 2020-12-06 18:56:35

如果你想要deepface,那么这可以通过几行代码来处理。此外,它是基于keras的库。这就是为什么,它很容易安装和运行。另一方面,face_recognition主要是基于dlib的,安装和运行都比较困难。

在这里,您需要将扩展名为.jpg或.png的面部图像存储在c:/文件夹中。

代码语言:javascript
复制
#!pip install deepface
from deepface import DeepFace
DeepFace.stream(db_path = "C:/facial_database", model_name = 'Facenet')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65154110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档