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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

【Python】调用百度云API人脸检测 Face Detect

發布時間:2025/4/5 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Python】调用百度云API人脸检测 Face Detect 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# encoding:utf-8 # !/usr/local/bin/python3# 百度云:駕駛行為分析 # 應用名稱:駕駛行為分析測試import urllib3 from urllib.parse import urlencode import urllib import urllib.request import sys import ssl import base64 import json''' # 調用API前必須獲取Access Token # client_id 為官網獲取的AK, client_secret 為官網獲取的SK # access_token: 要獲取的Access Token; # expires_in: Access Token的有效期(秒為單位,一般為1個月); ''' AppId = 16902753 ApiKey = 'rrRIfsvmI28bPFsRsSf0rrvH' SecretKey = 'TNMr27ErnzIHt2n4TlSZPuVG7xFZkSNS' host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + \ApiKey+'&client_secret='+SecretKey request = urllib.request.Request(host) request.add_header('Content-Type', 'application/json; charset=UTF-8') response = urllib.request.urlopen(request) content = response.read() if (content):#print(content) # 打印獲取到的信息# 通過decode將bytes字節串轉換為字符串strcontent = content.decode('utf-8')contentDict = json.loads(content) # 借助json函數將str轉換為dictrefresh_token = contentDict["refresh_token"] # 直接讀取dict字典內需要的數據expires_in = contentDict["expires_in"]session_key = contentDict["session_key"]access_token = contentDict["access_token"]scope = contentDict["scope"]session_secret = contentDict["session_secret"]#print(access_token)''' 人臉檢測與屬性分析 ''' request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect" # 人臉檢測 #imagePath = '/Users/zhaojichao/Desktop/face.jpeg' #imagePath = '/Users/zhaojichao/Downloads/mmexport1565091537318.jpg' # 測試100002 imagePath = '/Users/zhaojichao/Documents/證件照/IMG_4354電子版1寸.jpg' f = open(imagePath, 'rb') # img為bytes類型 img = base64.b64encode(f.read()) # img為str類型 img = img.decode('utf-8') '''face_field 否 string 包括age, beauty, expression, face_shape, gender, glasses, landmark, landmark150, race, quality, eye_status, emotion, face_type信息 逗號分隔. 默認只返回face_token、人臉框、概率和旋轉角度''' params = {"image": img,"image_type": "BASE64","face_field": "faceshape,facetype,age,beauty,gender"} # 對base64數據進行urlencode處理編碼之后格式為str params = urllib.parse.urlencode(params) # str轉為可以提交的bytes params = params.encode('utf-8') access_token = access_token request_url = request_url + "?access_token=" + access_token request = urllib.request.Request(url=request_url, data=params) request.add_header('Content-Type', 'application/json') response = urllib.request.urlopen(request) content = response.read() if content:# 返回數據為bytes,需要轉換為strcontent = content.decode('utf-8')print(content)

總結

以上是生活随笔為你收集整理的【Python】调用百度云API人脸检测 Face Detect的全部內容,希望文章能夠幫你解決所遇到的問題。

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