ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
52.91k stars 13.44k forks source link

Webcam example crashing when detects a face #1454

Open siddux opened 1 year ago

siddux commented 1 year ago

Description

I am trying to run the examples which uses the webcam. If any person appears in front of it the code works but when any face appears on the webcam it crashes with the following error:

Traceback (most recent call last):
  File "/home/erius/Documents/RAADICAL-face-recognition/test.py", line 42, in <module>
    face_encodings = face_recognition.face_encodings(rgb_frame, face_locations, 10)
  File "/home/erius/anaconda3/envs/face-recognition/lib/python3.9/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/erius/anaconda3/envs/face-recognition/lib/python3.9/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 0x7efd27db12b0>, array([[[ 13,  14,   9],
        [ 14,  15,  10],
        [ 12,  18,  11],
        ...,
        [ 20,  28,  16],
        [ 31,  36,  18],
        [ 34,  40,  22]],

       [[ 13,  14,   9],
        [ 14,  15,  10],
        [ 14,  15,   8],
        ...,
        [ 23,  32,  20],
        [ 29,  37,  18],
        [ 34,  42,  23]],

       [[ 12,  13,   6],
        [ 14,  15,   8],
        [ 14,  15,   8],
        ...,
        [ 24,  33,  21],
        [ 31,  39,  18],
        [ 35,  43,  22]],

       ...,

       [[105, 110,  95],
        [105, 110,  95],
        [105, 110,  97],
        ...,
        [ 14,  14,   3],
        [ 14,  14,   3],
        [ 14,  14,   3]],

       [[107, 109,  95],
        [107, 109,  95],
        [107, 109,  95],
        ...,
        [ 16,  15,   4],
        [ 16,  15,   4],
        [ 14,  14,   3]],

       [[108, 111,  94],
        [107, 110,  93],
        [107, 109,  95],
        ...,
        [ 16,  15,   4],
        [ 16,  15,   4],
        [ 16,  15,   4]]], dtype=uint8), <_dlib_pybind11.full_object_detection object at 0x7efd27db11f0>, 10

Any idea on where the problem can be?

ManivannanMurugavel commented 1 year ago

Try

rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

instead of

rgb_frame = frame[:, :, ::-1]
innerfirexy commented 1 year ago

@ManivannanMurugavel You are correct. I have the same issue on MacOS 12.6.1 and Python 3.9.6. It is fixed when changing the code from rgb_frame = frame[:, :, ::-1] to rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

uncrochet commented 1 year ago

Same issue, also worked for me Win10 and Python 3.11.1 and dlib-19.24.99 Many thanks for the fix. Might worths a commit to fix the examples ;)

Yaskoga commented 1 year ago

Same issue on Raspberry Pi4B Bullseye 64bit. It was fixed. Thanks, too

BirenMer commented 1 year ago

Thanks @ManivannanMurugavel my code is working now, I have also provided this answer in two above mentioned issue thank you once again