Introduction:

Hello! I’m Mumuzi. Did you miss me again today?

Wasn’t there a Python Beauty camera before? I don’t know if you remember? The topic of this issue is still around the previous issue about the level of appearance to go.

It’s the same recipe, it’s the same taste.

Every now and then a girl or a guy has had the experience of looking in the mirror and thinking that he or she is so beautiful that he or she explodes. [Xiaobian will not admit it. JPG]

But turn on the faceless front-facing camera with no filter, or see a real pretty sister, and wonder how ugly you can be!

Appearance rating is a controversial topic that everyone is interested in, so today Muko is here with the Python Appearance rating Tool!

** On a scale of 60 out of 100, ** how would you rate your appearance level?

The body of the

This article is based on tkinter interface appearance level scoring system ha, quick to measure your appearance level dozen how many points ah ~

Environment installation: Python3, 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
Copy the code

First of all, baidu API parameters must be configured 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'}
Copy the code

Title design color, font, etc. :

def title(self): Lb = tk.Label(self.root, text=' lightpink', bg='#008B8B', fg='lightpink', font=(' regular script ', 30), width=20, height=2, # relief=tk.SUNKEN ) lb.place(x=200, y=10)Copy the code

Set the background size of the interface program, etc. :

class ScoreSystem(): Root = tk.tk () # Change the size of the program box root. Geometry ('800x500') # Change the background color canvas = tk.canvas (root, Width =800, # specify Canvas component width height=500, # specify Canvas component height bg='#E6E8FA') # specify Canvas component background color Canvas.pack ()Copy the code

Fraction recognition part:

def face_score(file_path): """ face recognition score """ result = a_face.detect(get_file_content(file_path), image_type, options) print(result) age = result['result']['face_list'][0]['age'] beauty = result['result']['face_list'][0]['beauty']  gender = result['result']['face_list'][0]['gender']['type'] return age, beauty, genderCopy the code

Main function run:

def start_interface(self): "" self.title() self.time_component() # open local file tk.button (self.root, text=' open file ', Place (x=50, y=150) # tk.Button(self.root, text=' id ', Command =self.open_files2). Place (x=50, y=230) # exit tk.Button(self.root, text=' exit ', command=self. Tk. Label(self.root, text=' original ', font=10). Place (x=380, Self.label_img_original = tk.label (self.root) self.cv_orinial = tk.canvas (self.root) Self.cv_orinial. Create_rectangle (8, 8, rectangle, 260, width=1) Self.label_img_original. Place (x=265, y=150) self.label_img_original. Place (x=265, y=150) self.label_img_original. Place (x=680, y=150) self.text1 = tk. text (self.root, width=10, Place (x=680, y=250) self.text2 = tk. text (self.root, width=10, Place (x=680, y=350) self.text3 = tk. text (self.root, width=10, Place (x=680, y=175) self.text2.place(x=680, y=285) self.text3.place(x=680, y=285) self.text3.place(x=680, y=285) self.text3.place(x=680, y=285) Self.root.mainloop () def original_pic(self): Img = image.open (fr'{self.path_}') img = img.resize((270, 270), Pil.image.antialias) # generate tkinter Image object img_png_original = imagetk.photoImage (img) # set Image 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): Age, score, gender = face_score(self.path_) Tk.end) self.text1.tag_config('red', foreground=' red') self.text1.insert(tk.end, gender, 'red') self.text2.delete(1.0, foreground=' red') self.text1.tag_config('red', foreground=' red') self.text2.delete(1.0, Tk.end) self.text2.tag_config('red', foreground=' red') self.text2.insert(tk.end, age, 'red') self.text2.delete (1.0, foreground=' red') self.text2.tag_config('red', foreground=' red') self.text2.delete (1.0, tk.END) self.text3.tag_config('red', foreground='RED') self.text3.insert(tk.END, score, 'red') def quit(self): """ exit """ self.root.quit()Copy the code

Finally, the time group is also set up to update the time of testing the appearance level at any time, so that the appearance level of different periods can be measured.

def get_time(self, lb): "" time_str = time.strftime("%Y-%m-%d %H:% m :%S") # Fetch the current time and convert it to string lb.configure(text=time_str) # reset the tag text Self.root. after(1000, self.get_time, lb) # def time_component(self): "" "time component "is" "lb = tk. Label (self. The root, the text = ', fg = 'white', the font = (" black", 15)) lb. Place (relx = 0.75, Rely = 0.90) self. Get_time (lb)Copy the code

The effect is as follows:

Hey hey! Only for everyone to learn entertainment communication ha ~ a lot of appearance level mark forbids drop! If you offend me, please punch me gently.

conclusion

All right! This article is written here, this appearance level scoring magic device needs a small partner from yourself!

If you need a complete project source code + all material old rules source code base see: # private letter xiaobian 06# or click on the blue font you can get free source package!

Remember the third company oh ~ MUA your support is my biggest motivation!!