Introduction
Hello! I'm kimiko. Do you miss me again today?
Didn't you have a Python beauty camera before? I wonder if you remember? The topic of this issue still revolves around the beauty aspect of the previous issue.
Or the original formula, or the original taste.
Occasionally, girls or boys have had such an experience. When they look in the mirror, they feel so beautiful and handsome that they explode. [Xiaobian won't admit it. jpg]
But if you open the front camera without beauty, without filter, or see a really beautiful little sister, you will feel how you can be so ugly!
Selfie scoring is actually a controversial topic that everyone is interested in, so Muzi is coming with Python selfie scoring artifact today!
If the full score is 100 and the average score is 60, how would you rate your appearance?
text
This article is based on tkinter's interface beauty scoring system. Ha, come and test your beauty score~
Environment installation: Python 3, pycharm2021, and some built-in modules.
pip install -i https://pypi.douban.com/simple/ pillow pip install -i https://pypi.douban.com/simple/ baidu-aip
First, configure Baidu api parameters as follows:
APP_ID = '15768642' API_KEY = 'xhiiGmGPRCRj10XIqVlVeCky' SECRET_KEY = 'ZDMMAO7StwTKzW8BspVQxvoGtdgSW4yI' a_face = AipFace(APP_ID, API_KEY, SECRET_KEY) image_type = 'BASE64' options = {'face_field': 'age,gender,beauty'}
Title Design color, font, etc.:
def title(self): """Title Design""" lb = tk.Label(self.root, text='Face value scoring system', bg='#008B8B', fg='lightpink', font=('regular script', 30), width=20, height=2, # relief=tk.SUNKEN ) lb.place(x=200, y=10)
The background size of the interface program is set:
class ScoreSystem(): root = tk.Tk() # Modify the size of the program box root.geometry('800x500') # Add program box title root.title('Face value scoring system') # Modify background color canvas = tk.Canvas(root, width=800, # Specifies the width of the Canvas component height=500, # Specifies the height of the Canvas component bg='#E6E8FA') # Specifies the background color of the Canvas component canvas.pack()
Main function run:
def start_interface(self): """Main run function""" self.title() self.time_component() # Open local file tk.Button(self.root, text='Open file', command=self.show_original_pic).place(x=50, y=150) # Perform appearance value scoring tk.Button(self.root, text='Color recognition', command=self.open_files2).place(x=50, y=230) # Exit the system tk.Button(self.root, text='Exit software', command=self.quit).place(x=50, y=390) # Show border title tk.Label(self.root, text='Original drawing', font=10).place(x=380, y=120) # Modify picture size self.label_img_original = tk.Label(self.root) # Set the display border background self.cv_orinial = tk.Canvas(self.root, bg='white', width=270, height=270) # Set display border self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red') # Set position self.cv_orinial.place(x=265, y=150) # Show picture location self.label_img_original.place(x=265, y=150) # Set scoring label tk.Label(self.root, text='Gender', font=10).place(x=680, y=150) self.text1 = tk.Text(self.root, width=10, height=2) tk.Label(self.root, text='Age', font=10).place(x=680, y=250) self.text2 = tk.Text(self.root, width=10, height=2) tk.Label(self.root, text='score', font=10).place(x=680, y=350) self.text3 = tk.Text(self.root, width=10, height=2) # Filling text self.text1.place(x=680, y=175) self.text2.place(x=680, y=285) self.text3.place(x=680, y=385) # Open cycle self.root.mainloop() def show_original_pic(self): """Put file""" self.path_ = askopenfilename(title='Select file') # process the file img = Image.open(fr'{self.path_}') img = img.resize((270, 270), PIL.Image.ANTIALIAS) # Resize the picture to 270 * 270 # Generate tkinter picture object img_png_original = ImageTk.PhotoImage(img) # Set picture object self.label_img_original.config(image=img_png_original) self.label_img_original.image = img_png_original self.cv_orinial.create_image(5, 5, anchor='nw', image=img_png_original) def open_files2(self): # Get the age, score and gender obtained by Baidu API interface age, score, gender = face_score(self.path_) # Clear text box contents and insert self.text1.delete(1.0, tk.END) self.text1.tag_config('red', foreground='RED') self.text1.insert(tk.END, gender, 'red') self.text2.delete(1.0, tk.END) self.text2.tag_config('red', foreground='RED') self.text2.insert(tk.END, age, 'red') self.text3.delete(1.0, tk.END) self.text3.tag_config('red', foreground='RED') self.text3.insert(tk.END, score, 'red') def quit(self): """sign out""" self.root.quit()
Finally, a time group is also} set to update the time of testing the color value at any time, so that the color value in different time periods can be measured.
def get_time(self, lb): """Get time""" time_str = time.strftime("%Y-%m-%d %H:%M:%S") # Gets the current time and converts it to a string lb.configure(text=time_str) # Reset label text self.root.after(1000, self.get_time, lb) # Call the get function every 1s_ Time gets the time itself def time_component(self): """Time component""" lb = tk.Label(self.root, text='', fg='white', font=("Blackbody", 15)) lb.place(relx=0.75, rely=0.90) self.get_time(lb)
The effects are as follows:
Hey, hey! Just for everyone to learn, entertain and communicate ~ many selfies are not allowed to score! Please beat me gently. jpg.
summary
All right! The article is written here. This beauty scoring artifact needs a little partner to take it!
Remember the third consecutive oh ~mua, your support is my biggest motivation!!