资源简介
1,登录界面两个key值为百度云账号注册应用key值;
2,此demo为Qt调用Python函数,所以必须先配置环境,把python安装目录下的libs和include配到Qt中的pro文件中;
3,py文件需放到exe同文件夹下才可以正确运行;
4,使用说明:https://blog.csdn.net/hdaioutgjht/article/details/85331801

代码片段和文件信息
import urllib urllib.request sys
import ssl
import json
import base64
import urllib.parse
def getAccessToken(apiKeysecretKey):
# client_id 为官网获取的AK, client_secret 为官网获取的SK
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)
print(json.loads(content)[‘access_token‘])
return json.loads(content)[‘access_token‘]
def getResult(srcapiKeysecretKey):
print(‘go to python‘)
host = ‘https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=‘+getAccessToken(apiKeysecretKey)
request = urllib.request.Request(host)
request.add_header(‘Content-Type‘ ‘application/json; charset=UTF-8‘)
data = {}
print(‘4444‘)
data[‘image‘] = src
data[‘image_type‘]=‘base64‘
data[‘face_field‘]=‘agebeautygenderexpressionfaceshapeglassesrace‘
print(host)
data = urllib.parse.urlencode(data).encode(“utf-8“)
response = urllib.request.urlopen(requestdata=data)
print(‘go to python444‘)
content = response.read()
if (content):
print(content)
result = json.loads(content)[‘result‘][‘face_list‘][0]
#print(result[‘age‘]result[‘beauty‘]result[‘gender‘][‘type‘]result[‘expression‘][‘type‘]result[‘face_shape‘][‘type‘]result[‘glasses‘][‘type‘]result[‘race‘][‘type‘])
return (result[‘age‘]result[‘beauty‘]result[‘gender‘][‘type‘]result[‘expression‘][‘type‘]result[‘face_shape‘][‘type‘]result[‘glasses‘][‘type‘]result[‘race‘][‘type‘])
def main():
with open(“F:\\QtPro\\TestPython\\build-TestPython-Desktop_Qt_5_10_1_MSVC2015_64bit-Debug\\debug\\11.jpg““rb“) as f:
base64_data = base64.b64encode(f.read())
getResult(base64_data)
if __name__ == ‘__main__‘:
main()
# print(__name__)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-12-28 21:46 TestPython\
文件 2100 2018-12-28 17:25 TestPython\getAccessToken.py
文件 6854 2018-12-28 17:28 TestPython\login.ui
文件 5181 2018-12-28 21:44 TestPython\loginwidget.cpp
文件 5181 2018-12-28 21:45 TestPython\loginwidget.cpp.autosave
文件 720 2018-12-28 17:28 TestPython\loginwidget.h
文件 568 2018-12-28 20:21 TestPython\main.cpp
文件 1321 2018-12-28 20:30 TestPython\mainwindow.cpp
文件 555 2018-12-28 17:21 TestPython\mainwindow.h
文件 6227 2018-12-28 17:39 TestPython\mainwindow.ui
文件 209 2018-12-28 21:50 TestPython\ReadMe.txt.txt
文件 201 2018-12-28 21:28 TestPython\resource.qrc
文件 1375 2018-12-28 20:17 TestPython\TestPython.pro
文件 44421 2018-12-28 19:43 TestPython\TestPython.pro.user
文件 23817 2018-12-28 17:46 TestPython\TestPython.pro.user.bd9280d
文件 990 2018-12-28 20:33 TestPython\TestPython_zh.qm
文件 6552 2018-12-28 20:33 TestPython\TestPython_zh.ts
相关资源
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 15个pyqt5项目
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- pyqt5动态加载ui文件,动态加载背景图
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
评论
共有 条评论