First show you the effect picture, feel good, please refer to the realization of the code.
The specific code is shown below:
#!/usr/bin/env python # -*- coding:utf-8 -*- """ pip install pillow pip install baidu-aip pip install tkinter """ import PIL import time import base64 import tkinter as tk from PIL import Image from PIL import ImageTk from aip import AipFace from import askopenfilename # Configure Baidu aip parameters 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'} def get_file_content(file_path): """Get the contents of the document""" with open(file_path, 'rb') as fr: content = base64.b64encode(()) return ('utf8') def face_score(file_path): """Facial 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, gender class ScoreSystem(): """Scoring system class""" root = () # Modify the size of the program box ('800x500') # Add program box title ('Goddess/Godfather Face Scoring System') # Modify the background color canvas = (root, width=800, # Specify the width of the Canvas component height=500, # Specify the height of the Canvas component bg='#E6E6FA') # Specify the background color of the Canvas component () def start_interface(self): """Main Run Function""" () self.time_component() # Open a local file (, text='Open file', command=self.show_original_pic).place(x=50, y=150) # Make a face score (, text='Run the program', command=self.open_files2).place(x=50, y=230) # Show help documentation (, text='Help file', command=self.show_help).place(x=50, y=310) # Exit the system (, text='Exit the software', command=).place(x=50, y=390) # Display the title of the picture frame (, text='Original image', font=10).place(x=380, y=120) # Modify image size self.label_img_original = () # Setting up the display frame background self.cv_orinial = (, bg='white', width=270, height=270) # Setting up display frame borders self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red') # Set position self.cv_orinial.place(x=265, y=150) # Show image location self.label_img_original.place(x=265, y=150) # Set up scoring tags (, text='Gender', font=10).place(x=680, y=150) self.text1 = (, width=10, height=2) (, text='Age', font=10).place(x=680, y=250) self.text2 = (, width=10, height=2) (, text='Rating', font=10).place(x=680, y=350) self.text3 = (, width=10, height=2) # Fill in the text self.(x=680, y=175) self.(x=680, y=285) self.(x=680, y=385) # Start the cycle () def show_original_pic(self): """Into the file""" self.path_ = askopenfilename(title='Select file') # Processing documents img = (fr'{self.path_}') img = ((270, 270), ) # Resize the image to 270*270 # Generate tkinter image objects img_png_original = (img) # Setting up the 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 age, score, gender obtained from Baidu API interface age, score, gender = face_score(self.path_) # Clear text text box contents and insertion self.(1.0, ) self.text1.tag_config('red', foreground='RED') self.(, gender, 'red') self.(1.0, ) self.text2.tag_config('red', foreground='RED') self.(, age, 'red') self.(1.0, ) self.text3.tag_config('red', foreground='RED') self.(, score, 'red') def show_help(self): """Show help""" pass def quit(self): """Exit.""" () def get_time(self, lb): """Getting Time""" time_str = ("%Y-%m-%d %H:%M:%S") # Get the current time and convert it to a string (text=time_str) # Reset label text (1000, self.get_time, lb) # Call the function get_time itself every 1s to get the time def time_component(self): """Time Component""" lb = (, text='', fg='blue', font=("bold.", 15)) (relx=0.75, rely=0.90) self.get_time(lb) def title(self): """Title Design""" lb = (, text='Goddess/Godfather Face Scoring System', bg='#6495ED', fg='lightpink', font=('Chinese New Wei', 32), width=20, height=2, # relief= ) (x=200, y=10) score_system = ScoreSystem() score_system.start_interface()
summarize
The above is a small introduction to the use of python to realize the male god goddess face value scoring system, I hope to help you, if you have any questions please leave me a message, I will reply to you in time. Here also thank you very much for your support of my website!
If you find this article helpful, please feel free to reprint it, and please note the source, thank you!