Color value 065 scoring system Goddess

First, the introduction of

Yang Yang Mi and beyond in the end who is more beautiful, with Python made a goddess Yen value scoring system

065- color value goddess scoring system -11.jpg? X-oss-process = style / watermark

1.0.0.1 Blimey weather is getting hot friends, campus, beautiful little sister on the subway more and more, say summer is the season of love, when what is considered the beauty of it? In fact, I still feel pretty goddess on TV

~~ see a small gray beauty and small have begun theory up, and uncompromising.

065- color value goddess scoring system -02.jpg? X-oss-process = style / watermark

065- color value goddess scoring system -03.jpg? X-oss-process = style / watermark

065- color value goddess scoring system -04.jpg? X-oss-process = style / watermark

065- color value goddess scoring system -05.jpg? X-oss-process = style / watermark

Here's to say something about this color value scoring system I designed, first let us look at the picture effect, such as a look at how the value of Yen Yang Mi:

065- color value goddess scoring system -08.jpg? X-oss-process = style / watermark

How, the result is quite accurate now, we are not eager to have it? Here to explain the color value for a scoring system.

Second, the registration Baidu API

The system is the most central part of the value of scoring Yan, in fact, here is the direct uses Baidu face detection platform, large corporations, play shooting fly and secure, we only need to open the following URL:

http://ai.baidu.com/tech/face Then click "Use now" to create their own applications

065- color value goddess scoring system -06.jpg? X-oss-process = style / watermark

After creating the application, we will be able to get their APP_ID, API_KEY and SECRET_KEY value, as shown below:

065- color value goddess scoring system -07.jpg? X-oss-process = style / watermark

These three values ​​equivalent to our house number and key, only to have these values, we will be able to "open the door."

Third, Baidu API calls in Python

After we registered a good api, Baidu provides a Python interface can be installed directly after we use the very methods. Eliminating the trouble of our own with a deep learning to build the model, there are really good API.

  • Install pip install baidu-aip this package is very important, we must first install and then introduced AipFace this library;
  • Then we need to read out the picture, because the picture is a binary value, so we read with rb, then the binary data in base64 encryption, passed Baidu backend.
  • Then call aFace this interface, the data fed to it, get it json return value, we only took age, sex and color values.

The following look at the core of the code:

# 配置百度aip参数
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):
    """获取文件内容"""
    with open(file_path, 'rb') as fr:
        content = base64.b64encode(fr.read())

        return content.decode('utf8')


def face_score(file_path):
    """脸部识别分数"""
    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

Fourth, do a Tk interface

Because Python comes tk libraries, GUI more convenient to do, we value the Yen scoring system directly tk to complete. Interested partners can build a small web page with a game to play, we look at what we built the interface:

065-女神颜值打分系统-09.jpg?x-oss-process=style/watermark

Interface is very simple, the main function button on the left and right sides, the left is the input and operation, as well as the Help button on the right is the result of output, part of the core code are listed below:

    def start_interface(self):
        tk.Button(self.root, text='打开文件', command=self.show_original_pic).place(x=50, y=120)
        # 进行颜值评分
        tk.Button(self.root, text='运行程序', command=self.openfiles2).place(x=50, y=200)
        # 显示帮助文档
        tk.Button(self.root, text='帮助文档', command=self.show_help).place(x=50, y=280)
        # 退出系统
        tk.Button(self.root, text='退出软件', command=self.quit).place(x=50, y=40)

        tk.Label(self.root, text='原图', font=10).place(x=380, y=120)

        self.label_img_original = tk.Label(self.root)
        self.cv_orinial = tk.Canvas(self.root, bg='white', width=270, height=270)
        self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red')
        self.cv_orinial.place(x=260, y=150)
        self.label_img_original.place(x=260, y=150)

        tk.Label(self.root, text='性别', font=10).place(x=780, y=120)
        self.text1 = tk.Text(self.root, width=10, height=2, font=('Helvetica', 10))
        tk.Label(self.root, text='年龄', font=10).place(x=780, y=220)
        self.text2 = tk.Text(self.root, width=10, height=2, font=('Helvetica', 10))
        tk.Label(self.root, text='评分', font=10).place(x=780, y=320)
        self.text3 = tk.Text(self.root, width=10, height=2, font=('Helvetica', 10))
        # tk.Text.configure(font='\Library\Fonts\Heiti.ttc')

        self.text1.place(x=760, y=150)
        self.text1.place(x=760, y=250)
        self.text1.place(x=760, y=350)

        self.root.mainloop()

4 corresponding to the button functions are bound;

  • Open the file binding show_original_pic ()
  • Run the program bind open_file2 ()
  • Help file binding show_help ()
  • Exit the software binding quit ()

Such as our Open File button is binding show_original_pic this function, read the image file, use the PIL module reads the picture to read:

def show_original_pic(self):
    self.path_ = tk.askopenfilename(title='选择文件')
    print(self.path_)
    img = PIL.Image.open(fr'{self.path_}')
    img = img.resize((270,270),PIL.Image.ANTIALIAS)  # 调整图片大小至270*270
    img_png_original = tk.ImageTk.PhotoImage(img)
    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)

Click the Run button, is to call open_files2 function to take a picture in front of us face_core function analysis of age, color values, gender, and then fill in these three values ​​to the right of the text box.

Write so much, we want to know in the end is a high-value Yan Yan Yang Mi or higher than the value of Young's, I run the program a bit and found that it was high value Yan Yang Mi.

065-女神颜值打分系统-10.jpg?x-oss-process=style/watermark

Python is not it amazing fun, hands-automatic scoring system to create a color value, like the goddess with a digital to scoring. Imagine if Dilly Reba and Coulee Nazha PK, who is more to the United States.

Students may want to add my source micro-channel nickchen121

Guess you like

Origin www.cnblogs.com/nickchen121/p/11209875.html