D
D
dz_off2022-02-11 18:10:56
Python
dz_off, 2022-02-11 18:10:56

How to fix error when using face_recognition library?

It gives an error when using the face_recognition library, I can’t fix it for several days, all the necessary libraries are installed
62067c1288ef6050318192.jpeg

The code itself

import numpy as np
import face_recognition as fr
import cv2

video_capture = cv2.VideoCapture(0)

bruno_image = fr.load_image_file("bruno.jpg")
bruno_face_encoding = fr.face_encodings(bruno_image)[0]

known_face_encondings = [bruno_face_encoding]
known_face_names = ["Bruno"]

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()


And compilation errors
62067c4e6b133256745033.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dz_off, 2022-02-12
@dz_off

in the future, whoever encounters this problem, then remove dlib, face recognition and install them on python 3.6 in anaconda and everything will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question