ageitgey / face_recognition

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

compute_face_descriptor(): incompatible function arguments #1582

Open neilyoung opened 3 months ago

neilyoung commented 3 months ago

Description

I'm running into a problem with a fresh installation of dlib and face_recognition according to the doc. The sample code I ran is https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py

What I Did

python3 test.py

I'm getting this (and I'm getting this with various other samples too, so I suppose some incompatibility between face_recognition and dlib):

~/dlibtest$ python3 test.py
Traceback (most recent call last):
  File "/home/ubuntu/dlibtest/test.py", line 50, in <module>
    face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
  File "/usr/local/lib/python3.10/dist-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 "/usr/local/lib/python3.10/dist-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 0x7814e5b164b0>, array([[[164, 138,  99],
        [164, 138,  99],
        [164, 138,  99],
        ...,
        [ 93,  80,  57],
        [ 92,  79,  56],
        [ 92,  79,  56]],

       [[164, 138,  99],
        [164, 138,  99],
        [164, 138,  99],
        ...,
        [ 93,  80,  57],
        [ 92,  79,  56],
        [ 92,  79,  56]],

       [[164, 138,  99],
        [164, 138,  99],
        [164, 138,  99],
        ...,
        [ 97,  82,  62],
        [ 95,  80,  60],
        [ 95,  80,  60]],

       ...,

       [[ 59,  28,   5],
        [ 62,  31,   8],
        [ 66,  35,  12],
        ...,
        [119, 121, 117],
        [117, 119, 118],
        [107, 109, 109]],

       [[ 56,  25,   2],
        [ 60,  29,   6],
        [ 64,  33,  10],
        ...,
        [119, 121, 114],
        [116, 120, 115],
        [106, 111, 107]],

       [[ 56,  25,   2],
        [ 59,  28,   5],
        [ 62,  31,   8],
        ...,
        [118, 119, 113],
        [116, 120, 115],
        [111, 116, 112]]], dtype=uint8), <_dlib_pybind11.full_object_detection object at 0x7814e5af3e30>,
Suresh-vkl commented 3 months ago

Try this GRAY conversion before calling face_recognition.face_locations. It resolved this issue for me.

rgb_small_frame = small_frame[:, :, ::-1] rgb_small_frame = cv2.cvtColor(rgb_small_frame , cv2.COLOR_BGR2RGB) face_locations = face_recognition.face_locations(rgb_small_frame)

neilyoung commented 3 months ago

Yes, that solved the issue. Thanks

testvgg2024 commented 2 weeks ago

It is working.