最近網(wǎng)絡(luò)上爆火的藏族小哥哥丁真,大家都知道嗎?
十幾天前憑借一張純真、干凈、帥氣的臉霸屏各大短視頻平臺(tái),連各大電視臺(tái)新聞媒體都爭相報(bào)道,這個(gè)藏族小伙瞬間火了!!
網(wǎng)友們對(duì)于丁真的長相評(píng)價(jià)不一,我個(gè)人感覺是很帥的。
今天我使用百度AI的人臉識(shí)別,來看看人工智能會(huì)給丁真的顏值打多少分?
進(jìn)入百度AI開放平臺(tái)https://ai.baidu.com/
進(jìn)入控制臺(tái)并登錄賬號(hào)
進(jìn)入后進(jìn)入人臉識(shí)別,并創(chuàng)建應(yīng)用
創(chuàng)建成功可以在我的應(yīng)用看到密鑰

首先要獲取Access Token,可以查看官方的文檔
然后將圖片轉(zhuǎn)化為base64編碼
defimg_to_base64(slef,path):#圖片轉(zhuǎn)化為base64withopen(path,'rb')asf:image=f.read()image_base64=str(base64.b64encode(image),encoding='utf-8')returnimage_base64
查看文檔的主要請(qǐng)求參數(shù)
face_field參數(shù),默認(rèn)只返回人臉框、概率和旋轉(zhuǎn)角度。如果需要返回更多結(jié)果,可以在此參數(shù)中添加(beauty、age等)。
python完整代碼:
#encoding:utf8
import base64
import json
import requests
class BaiduAI:
def__init__(self,img):
self.AK=""#你的應(yīng)用API Key
self.SK=""#你的應(yīng)用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):
#圖片轉(zhuǎn)化為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表示證件照片,默認(rèn)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("人物顏值評(píng)分:",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("人物特征點(diǎn)位置:", 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()
下面是我找的兩張圖片:
從結(jié)果來看,丁真的顏值還是十分高的。
第二張圖片可能比較模糊,顏值分不太高哈哈哈
不愧是男神?。。。。?!
找高清圖片真的太難了?。?!
最后再找一張女神Lisa的照片看看顏值分多少吧。
太可了?。?!
教程領(lǐng)到手,學(xué)習(xí)不用愁!私信我即可免費(fèi)領(lǐng)取哦!
轉(zhuǎn)載:[……快樂的√4]
來源:CSDN