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 · 2 comments
Open

Closes Program #1614

TiagoCrippa opened this issue Oct 31, 2024 · 2 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()

@FeatureSpitter
Copy link

I have the same issue with their example: https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam.py

$ python facerec_from_webcam_faster.py
Traceback (most recent call last):
  File "/home/milhas/projectos/airport/face_recognition/examples/facerec_from_webcam_faster.py", line 55, in <module>
    face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
  File "/home/milhas/.local/lib/python3.10/site-packages/face_recognition/api.py", line 214, in face_encodings
    return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
  File "/home/milhas/.local/lib/python3.10/site-packages/face_recognition/api.py", line 214, in <listcomp>
    return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
TypeError: compute_face_descriptor(): incompatible function arguments. The following argument types are supported:
    1. (self: _dlib_pybind11.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),numpy.uint8], face: _dlib_pybind11.full_object_detection, num_jitters: int = 0, padding: float = 0.25) -> _dlib_pybind11.vector
    2. (self: _dlib_pybind11.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),numpy.uint8], num_jitters: int = 0) -> _dlib_pybind11.vector
    3. (self: _dlib_pybind11.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),numpy.uint8], faces: _dlib_pybind11.full_object_detections, num_jitters: int = 0, padding: float = 0.25) -> _dlib_pybind11.vectors
    4. (self: _dlib_pybind11.face_recognition_model_v1, batch_img: list[numpy.ndarray[(rows,cols,3),numpy.uint8]], batch_faces: list[_dlib_pybind11.full_object_detections], num_jitters: int = 0, padding: float = 0.25) -> _dlib_pybind11.vectorss
    5. (self: _dlib_pybind11.face_recognition_model_v1, batch_img: list[numpy.ndarray[(rows,cols,3),numpy.uint8]], num_jitters: int = 0) -> _dlib_pybind11.vectors

Invoked with: <_dlib_pybind11.face_recognition_model_v1 object at 0x7533edf50bb0>, array([[[119, 126, 126],
        [129, 131, 132],
        [130, 130, 135],
        ...,
        [ 71,  76,  88],
        [ 70,  71,  84],
        [ 74,  72,  84]],

       [[126, 127, 133],
        [128, 128, 134],
        [130, 130, 136],
        ...,
        [ 71,  75,  90],
        [ 69,  72,  85],
        [ 76,  77,  88]],

       [[125, 124, 133],
        [126, 126, 136],
        [126, 129, 140],
        ...,
        [ 71,  74,  88],
        [ 70,  75,  86],
        [ 71,  75,  87]],

       ...,

       [[ 82,  73,  52],
        [ 79,  71,  52],
        [ 79,  72,  52],
        ...,
        [ 64,  68,  76],
        [ 65,  68,  75],
        [ 64,  68,  72]],

       [[ 79,  71,  50],
        [ 71,  63,  43],
        [ 66,  55,  36],
        ...,
        [ 64,  66,  73],
        [ 63,  67,  72],
        [ 63,  67,  72]],

       [[ 51,  42,  25],
        [ 42,  32,  17],
        [ 49,  37,  25],
        ...,
        [ 66,  67,  74],
        [ 61,  65,  72],
        [ 61,  64,  72]]], dtype=uint8), <_dlib_pybind11.full_object_detection object at 0x7533ef7f7030>, 1

@JoelPC1000
Copy link

For me, it would just no error, while looking for solutions I found this that worked:
replace the code line, rgb_frame = frame[:, :, ::-1]
with below code line, rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
I'm
Windows: 11
Using
python: 3.12.7

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

3 participants