我是新手,很难解决这个问题。

我想做的是使用网络摄像头运行Face_recognition的示例代码。这两个示例都不适用于我,并且不断抛出此错误。

Traceback (most recent call last):
File "C:Users...Desktopface_recognitiondemo_webcam.py", line 55, in

face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:Users...AppDataLocalProgramsPythonPython311Libsite-packagesface_recognitionapi.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...AppDataLocalProgramsPythonPython311Libsite-packagesface_recognitionapi.py", line 214, in

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 的安装指南重新安装所有内容。

2

请更换代码行,

rgb_small_frame = frame_process[:, :, ::-1]
使用下面的代码行,

rgb_small_frame = numpy.ascontiguousarray(frame_process[:, :, ::-1])
分享
改进这个答案
跟随
4月5日 18:44 回复
Sahil Bandar 的用户头像
萨希尔班达尔
3655枚青铜徽章
非常感谢你做的这些。它终于起作用了。

布卡约
4 月 6 日 22:36
1
或者:rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)

贝克斯
5 月 4 日 0:18
解决问题