我是新手,很难解决这个问题。
我想做的是使用网络摄像头运行来自 face_recognition 的示例代码。这两个示例都不适用于我,并且不断抛出此错误。
Traceback (most recent call last):
File "C:\Users\...\Desktop\face_recognition\demo_webcam.py", line 55, in <module>
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\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\Local\Programs\Python\Python311\Lib\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 0x000001DAB486B7B0>, array([[[208, 223, 240],
[204, 213, 234],
[191, 208, 229],
...,
[ 87, 76, 74],
[ 94, 78, 77],
[ 82, 72, 70]],
[[214, 223, 245],
[208, 221, 240],
[197, 217, 235],
...,
[100, 63, 68],
[104, 74, 71],
[ 87, 78, 75]],
[[220, 231, 249],
[218, 228, 245],
[208, 224, 239],
...,
[ 96, 86, 84],
[102, 83, 82],
[ 86, 83, 80]],
...,
[[ 36, 36, 35],
[ 41, 37, 36],
[ 40, 35, 33],
...,
[107, 65, 41],
[109, 67, 44],
[109, 68, 50]],
[[ 41, 39, 38],
[ 42, 36, 35],
[ 44, 39, 38],
...,
[107, 64, 45],
[106, 62, 42],
[108, 64, 42]],
[[ 46, 42, 41],
[ 45, 39, 38],
[ 43, 38, 36],
...,
[104, 67, 51],
[100, 64, 46],
[108, 64, 40]]], dtype=uint8), <_dlib_pybind11.full_object_detection object at 0x000001DAB4EF0370>, 1
我正在使用在Windows 11上运行的Python 3.11.2。我有face_recognition v1.3.0和dlib v19.24.1。
我已经尝试根据face_recognition的安装指南重新安装所有内容。
请更换代码行,
rgb_small_frame = frame_process[:, :, ::-1]
使用下面的代码行,
rgb_small_frame = numpy.ascontiguousarray(frame_process[:, :, ::-1])
这就是答案
rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
你的代码工作得很好
任何人都可以告诉我到底应该在哪里进行更改,因为我找不到提到的 rgb_small_frame 行。谢谢你