face_recognition问题与face_encodings函数有关。

huangapple go评论110阅读模式
英文:

face_recognition problem with face_encodings function

问题

我是一个新手,遇到了解决这个问题的困难。

我尝试运行来自face_recognition的示例代码,使用网络摄像头。这两个示例都不适用于我,并且一直抛出这个错误。

我正在使用 Windows 11 上运行的 Python 3.11.2。我已经安装了 face_recognition v1.3.0 和 dlib v19.24.1。

我已经尝试按照 face_recognition 的安装指南重新安装了所有内容。

英文:

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 on throwing this error.

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 

I am using Python 3.11.2 running on Windows 11. I have face_recognition v1.3.0 and dlib v19.24.1.

I already tried reinstalling everything based on the installation guide from face_recognition.

答案1

得分: 5

请用以下代码行替换:

rgb_small_frame = numpy.ascontiguousarray(frame_process[:, :, ::-1])
英文:

Please replace the code line,

rgb_small_frame = frame_process[:, :, ::-1]

with below code line,

rgb_small_frame = numpy.ascontiguousarray(frame_process[:, :, ::-1])

答案2

得分: 0

rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)

your code worked bex

英文:

This is the answer

rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)

your code worked bex

huangapple
  • 本文由 发表于 2023年4月4日 15:36:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定