face_recognition/examples/facerec_from_webcam_faster.py at master · ageitgey/face_recognition
The world's simplest facial recognition api for Python and the command line - ageitgey/face_recognition
github.com
위 예제를 실행하자 다음과 같은 문제가 발생했다.
Traceback (most recent call last):
File "c:\Users\-\Documents\Project\Real-time-Streaming-Filter\tests\face_recognition\face_recognition_test.py", line 55, in <module>
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
File "C:\Users\-\AppData\Roaming\Python\Python310\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 "C:\Users\-\AppData\Roaming\Python\Python310\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 0x0000028EF5879DB0>, array([[[228, 239, 243],
[228, 239, 243],
[225, 236, 240],
...,
[133, 137, 136],
[130, 137, 135],
[127, 136, 133]],
[[233, 244, 248],
[233, 244, 248],
[230, 241, 245],
...,
[135, 139, 138],
[131, 139, 136],
[129, 138, 135]],
[[236, 247, 251],
[234, 245, 249],
[231, 242, 246],
...,
[136, 140, 139],
[132, 139, 137],
[131, 140, 137]],
...,
[[131, 142, 148],
[157, 168, 175],
[166, 177, 187],
...,
[154, 168, 177],
[154, 168, 177],
[154, 168, 177]],
[[143, 159, 168],
[167, 182, 195],
...,
[153, 167, 176],
[152, 166, 175],
[152, 166, 175]],
[[157, 175, 186],
[170, 188, 202],
[169, 186, 202],
...,
[153, 167, 176],
[151, 165, 174],
[151, 165, 174]]], dtype=uint8), <_dlib_pybind11.full_object_detection object at 0x0000028EF5F688B0>, 1
원인은 TypeError: compute_face_descriptor(): incompatible function arguments
코드 실행 시 발생한 오류의 원인은 face_recognition.face_encodings 함수에 넘겨준 인자의 형태와 호출 가능한 형태가 일치하지 않기 때문이다.
좀 더 구체적으로 살펴보면, 오류 메시지에서 다음과 같은 내용을 확인할 수 있다.
TypeError: compute_face_descriptor(): incompatible function arguments : 이 부분은 호출한 함수의 인자값이 정의된 형식과 맞지 않다는 오류를 의미한다. 다음에는 호출 가능한 compute_face_descriptor 함수의 서로 다른 형태 (overloading)에 대한 정의가 나열되어 있다.
해결방법
다행이도 StackOverFlow에 해결방법이 있었다.
face_recognition problem with face_encodings function
I am a newbie and having difficulty on resolving this issue. What I am trying to do is run the sample code from face_recognition using a webcam. Both of the two example doesn't work on me and keeps...
stackoverflow.com
요약하자면
rgb_small_frame = small_frame[:, :, ::-1]
의 51번째 해당 줄을
rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
으로 수정하면 된다.
'버그오류 해결' 카테고리의 다른 글
YOLOv8 torch 오류 해결 - Could not run ‘torchvision::nms’ with arguments from the ‘CUDA’ backend (2) | 2024.03.31 |
---|