如何使用 python 将 numpy.ndarray 的人脸编码附加到列表对象中

How can I append Face Encodings of numpy.ndarray into List Object using python

我正在将图像加载到 all_images 变量中,稍后我将它保存到 all_encodings 中以便稍后在我的代码中使用它,检查下面的代码:

all_images = glob.glob('images/*.jpg')

all_encodings = []

for images in all_images:
    image = fr.load_image_file(images)
    face_encode = fr.face_encodings(image)[0]

    print(face_encode)
    all_encodings = list(face_encode)
    all_encodings = list.append(face_encode)

print(all_encodings)

但它抛出以下错误

TypeError: descriptor 'append' requires a 'list' object but received a 'numpy.ndarray'..

请准确回答我的问题。提前致谢。

你在每次迭代中覆盖 all_encodings,我猜你想要:

all_images = glob.glob('images/*.jpg')

all_encodings = []

for images in all_images:
    image = fr.load_image_file(images)
    face_encode = fr.face_encodings(image)[0]

    print(face_encode)
    all_encodings.append(list(face_encode))

print(all_encodings)