最近爆火的帥小伙丁真在AI面前顏值多少分?


文章目錄

前言

一、具體過程

1.百度AI平台申請密鑰

2.python代碼實現

3.結果

二、悄悄看看明星的顏值分

彭於晏

王力宏

Lisa
前言

最近網絡上爆火的藏族小哥哥丁真,大家都知道嗎?

image

十幾天前憑借一張純真、干凈、帥氣的臉霸屏各大短視頻平台,連各大電視台新聞媒體都爭相報道,這個藏族小伙瞬間火了!!

網友們對於丁真的長相評價不一,我個人感覺是很帥的。

今天我使用百度AI的人臉識別,來看看人工智能會給丁真的顏值打多少分?

一、具體過程

1.百度AI平台申請密鑰

進入百度AI開放平台https://ai.baidu.com/

進入控制台並登錄賬號

進入后進入人臉識別,並創建應用

image

創建成功可以在我的應用看到密鑰

image

2.python代碼實現

首先要獲取Access Token,可以查看官方的文檔

image

然后將圖片轉化為base64編碼

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

查看文檔的主要請求參數

image

face_field參數,默認只返回人臉框、概率和旋轉角度。如果需要返回更多結果,可以在此參數中添加(beauty、age等)。

image

python完整代碼:

#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.結果

下面是我找的兩張圖片:

image

image

image

從結果來看,丁真的顏值還是十分高的。

第二張圖片可能比較模糊,顏值分不太高哈哈哈

二、悄悄看看明星的顏值分

彭於晏

image

image

不愧是男神啊!!!!!

王力宏

image

image

找高清圖片真的太難了!!!

最后再找一張女神Lisa的照片看看顏值分多少吧。

Lisa

image

image

太可了!!!

總結

以上就是文章的全內容
我是白白,一個喜歡學習喜歡編程的年輕人
想學習python的可以關注私信我哦~
歡迎小白、萌新、大佬加入我們
小白學習交流基地【(九七四)(七二四)(八九四)】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM