How much is the handsome boy Ding Zhen who has exploded recently in front of AI?

Ding Zhen, the Tibetan little brother who has recently exploded on the Internet, do you all know?

Ten days ago, with an innocent, clean, handsome face dominating all major short video platforms, even major TV news media rushed to report, this Tibetan guy instantly became popular! !

Netizens have different opinions on Ding Zhen's appearance. I personally feel that he is very handsome.

Today I use Baidu AI's face recognition to see how much artificial intelligence will give Ding Zhen's face value?

1. The specific process

1. Baidu AI platform application key

Enter Baidu AI open platform https://ai.baidu.com/

Enter the console and log in to the account

After entering, enter face recognition and create an application

You can see the key in my application

2.python code implementation

First, you need to get Access Token, you can check the official document

Then convert the picture to base64 encoding


defimg_to_base64(slef,path):#图片转化为
base64withopen(path,'rb')asf:image=f.read()
image_base64=str(base64.b64encode(image),encoding='utf-8')
returnimage_base64

View the main request parameters of the document


Recommendation: 020 is continuously updated, the small circle of boutiques has new content every day, and the concentration of dry goods is extremely high.
There are everything you want to make connections and discuss technology!
Be the first to join the group and outperform your peers! (There is no fee for joining the group)
Click here to communicate and learn with Python developers.
Group number: 745895701
application and delivery :
Python software installation package, Python actual combat tutorial,
free collection of materials, including Python basic learning, advanced learning, crawling, artificial intelligence, automated operation and maintenance, automated testing, etc.

The face_field parameter, by default only returns the face frame, probability and rotation angle. If you need to return more results, you can add it to this parameter (beauty, age, etc.).

Python complete code:

#encoding:utf8
import base64
import json
import requests

class BaiduAI:
        def__init__(self,img):
                self.AK=""#你的应用API Key
                self.SK=""#你的应用SecretKey
                self.img_src=img
                self.headers={"
                      Content-Type":"application/json; charset=UTF-8"}
        def get_AccessToken(self):
            #获取Access Token
            host='https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id='+self.AK+'&client_secret='+self.SK        
            response=requests.get(host,headers=self.headers)
            json_result=json.loads(response.text)
            if response:
                 returnjson_result['access_token']
             else:
             print(json_result)
             return 0

        def img_to_base64(slef,path):
              #图片转化为base64
              with open(path,'rb') as f:
                     image=f.read()
                     image_base64=str(base64.b64encode(image),encoding='utf-8')
              return image_base64
        def face_identification(self):
              # 人脸检测与属性分析        
              img=self.img_to_base64(self.img_src)
              request_url="https://aip.baidubce.com/rest/2.0/face/v3/detect"
              post_data={
                      "image":img,
                      "image_type":"BASE64",
                      "face_field":"gender,age,beauty,gender,race,emotion,face_shape,landmark",#包括age,beauty,expression,face_shape,gender,glasses,landmark,emotion,face_type,mask,spoofing信息
                      "face_type":"LIVE"#人脸的类型。LIVE表示生活照,IDCARD表示身份证芯片照,WATERMARK表示带水印证件照,CERT表示证件照片,默认LIVE。}
                access_token = self.get_AccessToken()
                request_url = request_url+"?access_token=" + access_token              
                response = requests.post(url=request_url,data=post_data,headers=self.headers)
json_result=json.loads(response.text)
                print(json_result)
                if json_result['error_code'] == 0:
                print("人脸表情:",json_result['result']['face_list'][0]['emotion']['type'])
                print("人物年龄:",json_result['result']['face_list'][0]['age'])
                print("人物颜值评分:",json_result['result']['face_list'][0]['beauty'])
                print("人物性别:",json_result['result']['face_list'][0]['gender']['type'])
                print("人物种族:",json_result['result']['face_list'][0]['race']['type'])
                #print("人物特征点位置:", json_result['result']['face_list'][0]['landmark72'])
        else:
              print(json_result['error_code'])
              print(json_result['error_msg'])
if __name__ == '__main__':
      imglist=['dingzhen1.jpg','dingzhen2.jpg']
      for i in range(0,len(imglist)):
            print('第{}张图片:'.format(i+1))
            demo=BaiduAI(imglist[i])
            if(demo.get_AccessToken()):
                  demo.face_identification()

3. Results

Here are the two pictures I found:

From the results, Ding Zhen's appearance is still very high.

The second picture may be blurry, the face value is not too high hahaha

Second, quietly look at the star's appearance score

Peng Yuyan

Worthy of being a male god! ! ! ! !

Wang Leehom

It's really hard to find high-resolution images! ! !

Finally, find a picture of the goddess Lisa to see how much she looks.

Lisa

That's great! ! !

Guess you like

Origin blog.csdn.net/Python_xiaobang/article/details/113115137