Я хочу сохранить face_encodings в существующем файле face_encoding с модулем face_recognition, но я не могу этого сделать!Вот код, но без сохранения face_encodings с существующим в файле face_encoding:
def addorThat():
def sel():
root.filename = filedialog.askopenfilename(initialdir="/", title="Select file",
filetypes=(("Photo Files", "*.jpg"), ("all files", "*.*")))
Label(lower_frame, text='File Location : ' + str(root.filename), font=40).pack()
with open('text_required.txt', 'w') as f:
f.write((root.filename))
return root.filename
def train():
print(entry.get())
if str(entry.get()) != None:
with open('text_required.txt', 'r') as f:
u = f.read()
print(u)
boxes = face_recognition.load_image_file(str(u))
all_encodings[entry.get()] = face_recognition.face_encodings(boxes)[0]
messagebox.showinfo('Doing', 'Training has started!')
with open('dataset_face.dat', 'wb') as f:
pickle.dump(all_encodings, f)
messagebox.showinfo('Done', 'Training Completed')
else:
messagebox.showerror('No Name', 'Please enter the person name to train!')
inputvar = StringVar()
root = tk.Toplevel()
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
background_image = tk.PhotoImage(file='landscape.png')
background_label = tk.Label(root, image=background_image)
background_label.place(relwidth=1, relheight=1)
frame = tk.Frame(root, bg='#80c1ff', bd=5)
frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')
inputvar.set("Person Name")
entry = tk.Entry(frame, font=40, textvariable=inputvar)
entry.place(relwidth=0.65, relheight=1)
button = tk.Button(frame, text="Take Picture", font=40, command=None)
button.place(relx=0.7, relheight=1, relwidth=0.3)
lower_frame = tk.Frame(root, bg='#80c1ff', bd=9)
lower_frame.place(relx=0.5, rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')
label = tk.Label(lower_frame)
label.place(relwidth=1, relheight=1)
but = tk.Button(lower_frame, text="Select Photo", font=40, command=sel)
but.pack()
# Label(lower_frame,text='File Location : '+str(sel),font =40).pack()
butt = Button(lower_frame, text='Train', font=40, command=train)
butt.pack()
scroll = Scrollbar(lower_frame, orient=VERTICAL)
scroll.pack(side=BOTTOM, fill=X)
scrollbar = Scrollbar(lower_frame, orient=HORIZONTAL)
scrollbar.pack(side=RIGHT, fill=Y)
root.mainloop()
Если вам нужна дополнительная информация, пожалуйста, сообщите мне!