日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > ChatGpt >内容正文

ChatGpt

百度AI——人脸识别案例

發布時間:2024/1/8 ChatGpt 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 百度AI——人脸识别案例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

人臉分析

import requests, base64def get_access_token():url = 'https://aip.baidubce.com/oauth/2.0/token'data = {'grant_type': 'client_credentials', # 固定值'client_id': '', # 在開放平臺注冊后所建應用的API Key'client_secret': '' # 所建應用的Secret Key}res = requests.post(url, data=data)res = res.json()access_token = res['access_token']return access_tokendef get_json(img):access_token=get_access_token()request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect"file = open(img, 'rb') # 二進制讀取圖片base64_data = base64.b64encode(file.read()) # 將圖片進行base64編碼base64_code = base64_data.decode()params = {'image': base64_code,'image_type': 'BASE64','face_field': 'age,beauty,expression,face_shape,gender,glasses,landmark,landmark150,quality,eye_status,emotion,face_type,mask,spoofing'}request_url = request_url + "?access_token=" + access_tokenheaders = {'Content-Type': 'application/json'}response = requests.post(request_url, data=params, headers=headers)if response:return response.json()if __name__ == '__main__':img = './img/mjl.jpg'json_data=get_json(img)

返回結果說明

必選類型說明
face_numint檢測到的圖片中的人臉數量
face_listarray人臉信息列表,具體包含的參數參考下面的列表。
+face_tokenstring人臉圖片的唯一標識 (人臉檢測face_token有效期為60min)
+locationarray人臉在圖片中的位置
++leftdouble人臉區域離左邊界的距離
++topdouble人臉區域離上邊界的距離
++widthdouble人臉區域的寬度
++heightdouble人臉區域的高度
++rotationint64人臉框相對于豎直方向的順時針旋轉角,[-180,180]
+face_probabilitydouble人臉置信度,范圍【0~1】,代表這是一張人臉的概率,0最小、1最大。其中返回0或1時,數據類型為Integer
+anglearray人臉旋轉角度參數
++yawdouble三維旋轉之左右旋轉角[-90(左), 90(右)]
++pitchdouble三維旋轉之俯仰角度[-90(上), 90(下)]
++rolldouble平面內旋轉角[-180(逆時針), 180(順時針)]
+agedouble年齡 ,當face_field包含age時返回
+beautyint64美丑打分,范圍0-100,越大表示越美。當face_fields包含beauty時返回
+expressionarray表情,當?face_field包含expression時返回
++typestringnone:不笑;smile:微笑;laugh:大笑
++probabilitydouble表情置信度,范圍【0~1】,0最小、1最大。
+face_shapearray臉型,當face_field包含face_shape時返回
++typedoublesquare: 正方形?triangle:三角形?oval: 橢圓?heart: 心形?round: 圓形
++probabilitydouble置信度,范圍【0~1】,代表這是人臉形狀判斷正確的概率,0最小、1最大。
+genderarray性別,face_field包含gender時返回
++typestringmale:男性?female:女性
++probabilitydouble性別置信度,范圍【0~1】,0代表概率最小、1代表最大。
+glassesarray是否帶眼鏡,face_field包含glasses時返回
++typestringnone:無眼鏡,common:普通眼鏡,sun:墨鏡
++probabilitydouble眼鏡置信度,范圍【0~1】,0代表概率最小、1代表最大。
+eye_statusarray雙眼狀態(睜開/閉合)?face_field包含eye_status時返回
++left_eyedouble左眼狀態 [0,1]取值,越接近0閉合的可能性越大
++right_eyedouble右眼狀態 [0,1]取值,越接近0閉合的可能性越大
+emotionarray情緒?face_field包含emotion時返回
++typestringangry:憤怒?disgust:厭惡?fear:恐懼?happy:高興?sad:傷心?surprise:驚訝?neutral:無表情?pouty: 撅嘴?grimace:鬼臉
++probabilitydouble情緒置信度,范圍0~1
+face_typearray真實人臉/卡通人臉?face_field包含face_type時返回
++typestringhuman: 真實人臉?cartoon: 卡通人臉
++probabilitydouble人臉類型判斷正確的置信度,范圍【0~1】,0代表概率最小、1代表最大。
+maskarray口罩識別?face_field包含mask時返回
++typeint沒戴口罩/戴口罩 取值0或1?0代表沒戴口罩 1 代表戴口罩
++probabilitydouble置信度,范圍0~1
+landmarkarray4個關鍵點位置,左眼中心、右眼中心、鼻尖、嘴中心。face_field包含landmark時返回
+landmark72array72個特征點位置?face_field包含landmark72時返回
+landmark150array150個特征點位置?face_field包含landmark150時返回
+qualityarray人臉質量信息。face_field包含quality時返回
++occlusionarray人臉各部分遮擋的概率,范圍[0~1],0表示完整,1表示不完整
+++left_eyedouble左眼遮擋比例,[0-1] ,1表示完全遮擋
+++right_eyedouble右眼遮擋比例,[0-1] , 1表示完全遮擋
+++nosedouble鼻子遮擋比例,[0-1] , 1表示完全遮擋
+++mouthdouble嘴巴遮擋比例,[0-1] , 1表示完全遮擋
+++left_cheekdouble左臉頰遮擋比例,[0-1] , 1表示完全遮擋
+++right_cheekdouble右臉頰遮擋比例,[0-1] , 1表示完全遮擋
+++chindouble下巴遮擋比例,,[0-1] , 1表示完全遮擋
++blurdouble人臉模糊程度,范圍[0~1],0表示清晰,1表示模糊
++illuminationdouble取值范圍在[0~255], 表示臉部區域的光照程度 越大表示光照越好
++completenessint64人臉完整度,0或1, 0為人臉溢出圖像邊界,1為人臉都在圖像邊界內
+spoofingdouble判斷圖片是否為合成圖

人臉對比

import requests, base64def get_access_token():url = 'https://aip.baidubce.com/oauth/2.0/token'data = {'grant_type': 'client_credentials', # 固定值'client_id': '', # 在開放平臺注冊后所建應用的API Key'client_secret': '' # 所建應用的Secret Key}res = requests.post(url, data=data)res = res.json()access_token = res['access_token']return access_token# 根據圖片名讀取圖片,并轉換成base64 def read_img(img):with open(img, 'rb') as f:base64_data = base64.b64encode(f.read())base64_code = base64_data.decode()return base64_codedef get_json(img1,img2):request_url = "https://aip.baidubce.com/rest/2.0/face/v3/match"params = [{"image": img1,"image_type": "BASE64","face_type": "LIVE","quality_control": "LOW","liveness_control": "HIGH"},{"image": img2,"image_type": "BASE64","face_type": "LIVE","quality_control": "LOW","liveness_control": "HIGH"}]access_token = get_access_token()request_url = request_url + "?access_token=" + access_tokenheaders = {'content-type': 'application/json'}response = requests.post(request_url, json=params, headers=headers)if response:return response.json()if __name__ == '__main__':img1 = read_img('img/mm2.jpeg')img2 = read_img('img/mjl.jpg')json_data=get_json(img1,img2)print(json_data)if json_data['error_msg'] == 'SUCCESS':score = json_data['result']['score']if score > 80:print("照片相似度為:" + str(score) + "基本確定是本人")else:print("照片相似度為:" + str(score) + "基本確定不是本人")print(score)else:print('錯誤信息:', json_data['error_msg'])

返回結果說明

參數名必選類型說明
scorefloat人臉相似度得分,推薦閾值80分
face_listarray人臉信息列表
+face_tokenstring人臉的唯一標志

人臉融合

import requests import base64 import json# 獲取token def get_access_token():url = 'https://aip.baidubce.com/oauth/2.0/token'data = {'grant_type': 'client_credentials', # 固定值'client_id': '', # 在開放平臺注冊后所建應用的API Key'client_secret': '' # 所建應用的Secret Key}res = requests.post(url, data=data)res = res.json()access_token = res['access_token']return access_token# 根據圖片名讀取圖片,并轉換成base64 def read_photo(name):with open(name, 'rb') as f:base64_data = base64.b64encode(f.read())base64_code = base64_data.decode()return base64_code# 調用百度的接口,實現融合圖片 def face_fusion(template, target):access_token = get_access_token()url = 'https://aip.baidubce.com/rest/2.0/face/v1/merge'request_url = url + '?access_token=' + access_tokenparams = {"image_template": {"image": template,"image_type": "BASE64","quality_control": "NONE"},"image_target": {"image": target,"image_type": "BASE64","quality_control": "NONE"},"merge_degree": "NORMAL"}params = json.dumps(params)headers = {'content-type': 'application/json'}result = requests.post(request_url, data=params, headers=headers).json()if result['error_code'] == 0:res = result["result"]["merge_image"]down_photo(res)else:print(str(result['error_code'])+result['error_msg'])# 下載融合后圖片 def down_photo(data):imagedata = base64.b64decode(data)file = open('./result.jpg', "wb")file.write(imagedata)# 主程序 if __name__ == '__main__':template = read_photo('img/jjy.jpg')target = read_photo('img/mzc.jpeg')face_fusion(template, target)

返回結果說明

字段類型說明
merge_imagestring融合圖的BASE64值

人像動漫畫

import requests, base64# 百度AI開放平臺鑒權函數 def get_access_token():url = 'https://aip.baidubce.com/oauth/2.0/token'data = {'grant_type': 'client_credentials', # 固定值'client_id': '', # 在開放平臺注冊后所建應用的API Key'client_secret': '' # 所建應用的Secret Key}res = requests.post(url, data=data)res = res.json()access_token = res['access_token']return access_tokendef image_process(img_before, img_after, how_to_deal):# 函數的三個參數,一個是轉化前的文件名,一個是轉化后的文件名,均在同一目錄下,第三個是圖像處理能力選擇request_url = 'https://aip.baidubce.com/rest/2.0/image-process/v1/' + how_to_dealif how_to_deal == 'style_trans': # 判斷如果是 圖像風格化,需要額外添加一個風格配置others = 'cartoon' # 風格化參數,具體可設置范圍參見下面注釋'''cartoon:卡通畫風格pencil:鉛筆風格color_pencil:彩色鉛筆畫風格warm:彩色糖塊油畫風格wave:神奈川沖浪里油畫風格lavender:薰衣草油畫風格mononoke:奇異油畫風格scream:吶喊油畫風格gothic:哥特油畫風格'''else:others = ''file = open(img_before, 'rb') # 二進制讀取圖片origin_img = base64.b64encode(file.read()) # 將圖片進行base64編碼headers = {'Content-Type': 'application/x-www-form-urlencoded'}data = {'access_token': get_access_token(),'image': origin_img,"type":'anime_mask',"mask_id":"2"}res = requests.post(request_url, data=data, headers=headers)res = res.json()print(res)if res:f = open(img_after, 'wb')after_img = res['image']after_img = base64.b64decode(after_img)f.write(after_img)f.close()if __name__ == '__main__':img_before = 'img/mm1.jpg' # 當前目錄下的圖片img_after = img_before.split('.') # 將原文件名分成列表img_after = img_after[0] + '_2.' + img_after[1] # 新生成的文件名為原文件名上加 _1image_process(img_before, img_after, 'selfie_anime')# 第三個參數: selfie_anime 為人像動漫化,colourize 圖像上色,style_trans 為圖像風格化print('done!')

返回結果說明

字段是否必選類型說明
log_iduint64唯一的log id,用于問題定位
imagestring處理后圖片的Base64編碼

總結

以上是生活随笔為你收集整理的百度AI——人脸识别案例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。