【发布时间】:2021-01-15 20:44:58
【问题描述】:
我有以下代码从照片中提取人脸。现在我想从一个目录中提取它,即一次提取多个文件。 这应该非常简单,就像只是将“MultiPeople/Faces/IMG100”更改为“MultiPeople/Faces”,即整个目录。但我一直在代码下方出现错误。我已经完成了所有常规检查,例如确保帐户是管理员,确保文件或目录没有同时打开等等。
from PIL import Image
import face_recognition
path = r"C:\Users\Julio\Desktop\Face Extraction\Output\face"
image = face_recognition.load_image_file('MultiPeople/Faces')
face_locations = face_recognition.face_locations(image)
print("I found {} face(s) in this photograph.".format(len(face_locations)))
face_counter = 0
for face_location in face_locations:
top, right, bottom, left = face_location
print("I found a face in image location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
pil_image.save(str(path) + str(face_counter) + ".jpg")
face_counter += 1
Traceback (most recent call last):
File "C:\Users\Julio\PycharmProjects\test\Extract faces from photo.py", line 5, in <module>
image = face_recognition.load_image_file('MultiPeople/Faces')
File "C:\Users\Julio\PycharmProjects\test\venv\lib\site-packages\face_recognition\api.py", line 86, in load_image_file
im = PIL.Image.open(file)
File "C:\Users\Julio\PycharmProjects\test\venv\lib\site-packages\PIL\Image.py", line 2878, in open
fp = builtins.open(filename, "rb")
PermissionError: [Errno 13] Permission denied: 'MultiPeople/Faces'
【问题讨论】:
标签: python-3.x face-recognition