[英]Python - Load all images from Directory for facial recognition
images = "./img/known/*.jpg"
#Add known images
image_of_person = face_recognition.load_image_file(images)
person_face_encoding = face_recognition.face_encodings(image_of_person)[0]
I am getting the following error:我收到以下错误:
[Errno 22] Invalid argument: './img/known/*.jpg'
Is there anyway I can take all .jpg items in the folder "Known" and then use that as the 'Face to look for'?无论如何,我可以将“已知”文件夹中的所有 .jpg 项目用作“要查找的人脸”吗?
For example if a folder has 5 .jpg files of faces, can I take all 5 images and have the code search all faces?例如,如果一个文件夹有 5 个 .jpg 人脸文件,我可以拍摄所有 5 张图像并让代码搜索所有人脸吗?
Use用
for x in os.listdir(path):
And if you have other files in the directory than jpg use如果目录中有其他文件而不是 jpg 使用
if x.split(".jpg"):
#something
You have to use a for loop to achieve this.您必须使用 for 循环来实现此目的。 I have shown an example using Pillow library
我已经展示了一个使用 Pillow 库的示例
from PIL import Image
import glob
image_list = []
for Imagename in glob.glob('yourpath/*.jpg'):
im=Image.open(Imagename)
image_list.append(im)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.