Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes Program #1614

Open
TiagoCrippa opened this issue Oct 31, 2024 · 0 comments
Open

Closes Program #1614

TiagoCrippa opened this issue Oct 31, 2024 · 0 comments

Comments

@TiagoCrippa
Copy link

  • face_recognition version:
  • Python version: 3.12.6
  • Operating System: windows 11

Description

The package terminates my program every time it recognizes a face and the following error appears:

erro error

Code

import cv2
import face_recognition

video_capture = cv2.VideoCapture(0)

exemplo_imagem = face_recognition.load_image_file("exemplo.jpg")
exemplo_face_encodings = face_recognition.face_encodings(exemplo_imagem)

if len(exemplo_face_encodings) > 0:
exemplo_face_encoding = exemplo_face_encodings[0]
else:
print("Nenhum rosto encontrado na imagem de exemplo.")
video_capture.release()
cv2.destroyAllWindows()
exit()

conhecidos_face_encodings = [exemplo_face_encoding]
conhecidos_nomes = ["Exemplo"]

while True:
ret, frame = video_capture.read()
if not ret:
print("Não foi possível capturar o quadro.")
break

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


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

for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
    matches = face_recognition.compare_faces(conhecidos_face_encodings, face_encoding)
    name = "Desconhecido"

    if True in matches:
        first_match_index = matches.index(True)
        name = conhecidos_nomes[first_match_index]

    cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
    cv2.putText(frame, name, (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)

cv2.imshow('Video', frame)

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

video_capture.release()
cv2.destroyAllWindows()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant