问题描述
因此,我正在python3中制作一个程序,该程序获取人脸图像并标记人脸。我想添加一个ui,它只是一个弹出窗口,您可以在其中将图像目录与您要标识的人放在一起。当我不得不去对目录进行硬编码时,该程序运行良好,但是即使我使弹出窗口不执行任何操作,它仍然会干扰某些事情,并给我这个错误。
AttributeError:类型对象'ImageDraw'没有属性'Draw'
这是代码
^(.*Hello)?(.*?)(Goodbye.*)?$
我用Name1和Name2替换了名称。 当我删除Tkinter(以及所有弹出窗口的内容)时,它工作正常。 我添加了Pil作为pl的一部分,并添加了pl.blah,并修复了一个错误
pil_image = pl.Image.fromarray(test_image)
它最初只是import face_recognition
from PIL import Image,ImageDraw as pl
from tkinter import *
from tkinter import simpledialog
def get_me():
s = simpledialog.askstring("input string","enter name")
print(s)
window = Tk()
button = Button(window,text="popup",command=get_me)
button.pack()
window.geometry("300x300")
window.mainloop()
Name1_kNown = face_recognition.load_image_file('./img/kNown/Name1KNown.jpg')
Name1_encoding = face_recognition.face_encodings(Name1_kNown)[0]
print("[1] is done")
Name2_kNown = face_recognition.load_image_file('./img/kNown/Name2kNown.png')
Name2_encoding = face_recognition.face_encodings(Name2_kNown)[0]
print("[2] is done")
#create array of encodings and names
print("creating arrays")
kNown_face_encodings = [
Name1_encoding,Name1_encoding
]
kNown_face_names = [
"Name1\nLastName1","Name2\nLastName2"
]
#Load test image to find faces in
test_image = face_recognition.load_image_file('./img/unkNown/Name1UnkNown.png')
# find faces
face_locations = face_recognition.face_locations(test_image)
face_encodings = face_recognition.face_encodings(test_image,face_locations)
#convert to PIL
pil_image = pl.Image.fromarray(test_image)
#create ImageDraw
pl.draw = pl.ImageDraw.Draw(pil_image)
#loop through faces
for(top,right,bottom,left),face_encodings in zip(face_locations,face_encodings):
matches = face_recognition.compare_faces(kNown_face_encodings,face_encodings)
name = "UnkNown\nPerson"
print("unable to find kNown faces")
# If match
if True in matches:
print("scanning faces")
first_match_index = matches.index(True)
name = kNown_face_names[first_match_index]
#Draw Box
print("drawing Boxes")
draw.rectangle(((left,top),(right,bottom)),outline=(0,0))
#draw label
text_width,text_height = draw.textsize(name)
draw.rectangle(((left,bottom + text_height + 8),fill=(0,0),0))
draw.text((left + 6,bottom + text_height - 20),name,fill=(255,255,255))
del draw
#display
pil_image.show()
我对python经验不足,无法自行修复错误,因此将不胜感激。
另外有时我会忘记写东西,因为我认为打字的速度比我快,而且我在检查段落时视而不见,因此请在需要时进行澄清。 :D
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)