为什么在Python中face_recognition模块对我不起作用?

问题描述 投票:0回答:2

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

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”。但它仍然要求我安装该模块。你能帮忙吗?

这是我的代码:-

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()
python opencv face-recognition
2个回答
0
投票

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

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

#!pip install deepface
from deepface import DeepFace
DeepFace.stream(db_path = "C:/facial_database", model_name = 'Facenet')

0
投票

我通过以下方式解决了这个问题:

  1. 安装了旧版本的 dlib 软件包:pip install dlib==19.21.1
  2. 使用了 --no-cache-dir 标志:pip install --no-cache-dir face_recognition
© www.soinside.com 2019 - 2024. All rights reserved.