当调用face_encodings函数时,我遇到了以下错误。
TypeError: __call__(): incompatible function arguments. The following argument types are supported: 1. (self: dlib.fhog_object_detector, image: array, upsample_num_times: int=0) -> dlib.rectanglesInvoked with: <dlib.fhog_object_detector object at 0x7f066f834340>, '36121754-36121734.jpg', 2
这是我的代码
img = plt.imread(face) plt.imshow(img) x=face_recognition.load_image_file(face) x_code = face_recognition.face_encodings(face)[0]
图像路径是正确的,因为我尝试输出图像时,它显示load_image_file()已经执行并返回了一个数字数组。
我不确定哪里出了问题。
可能的错误原因是load_image_file或face_encodings的输入类型。
回答:
问题出在传递给face_encoding()的参数变量上。
正确的做法是:
x=face_recognition.load_image_file(face)x_code = face_recognition.face_encodings(x)[0]
原因是:
根据face-recognition库,load_image_file是一个初始函数,我们将文件传递给它并存储在一个变量中(在我这里是变量x
)。
之后,对于face_recognition包的任何其他函数,我们必须传递变量x
,而不是文件名。
PS:那错误详情仍然让我感到害怕