face_recognition
face_recognition copied to clipboard
compute_face_descriptor(): incompatible function arguments
- face_recognition version: 1.2.3
- Python version: 3.10.12
- Operating System: Ubuntu 22.04
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
- Provided obama.jpg and biden.jpg in the root of my project
- Created a test.py which is literally the sample code from_webcam_faster.py, but video capture replaced by RTSP input and video display replaced by image write. I can share the code, if required.
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>,
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)
Yes, that solved the issue. Thanks
It is working.
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)
thank u so much :)
您好,悉获您的邮件,我将尽快处理,感谢您的来信!
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)
Thanks the solution.
If I am understand right, the face_recognition function need continious array and not shadow copy of partial image array?
Also shorter solution which is behind the cvtColor function:
rgb_small_frame = np.copy(rgb_small_frame)
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)
Thanks the solution.
If I am understand right, the face_recognition function need continious array and not shadow copy of partial image array?
Also shorter solution which is behind the cvtColor function:
rgb_small_frame = np.copy(rgb_small_frame)
It's been a while since I worked on this module. But IIRC, the face recognition could compare the data it receives from your cam against the stored file, only if the RGB images had been converted to GRAY. I didn't try this np.copy(rgb_small_frame) then. But if it works, definitely a shorter solution. Happy to learn :)
您好,悉获您的邮件,我将尽快处理,感谢您的来信!