百度智能云的使用——以人脸识别为例
先进入这个界面:https://console.bce.baidu.com/ai/#/ai/face/overview/index
创建好应用后 点击图片右下角的免费获取资源(把能获取的都获取来)
点击管理应用 然后查看左边的技术文档
在API文档中找到想要的技术
根据提示 获得需要的access_token 这里的AK和SK在上面的第二张图中 从resopnse.json()中选择["access_token"]并返回
def getAccess(AK="CZ1HCPYGjXvlRVEGKR5XCIWT",SK="xT1CfbqzUa9xFAittlnS8ibc4tL4nTFn"):# client_id 为官网获取的AK, client_secret 为官网获取的SKhost = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={}&client_secret={}'.format(AK,SK)response = requests.get(host)if response:print(response.json()["access_token"])return (response.json()["access_token"])
将access_token替换 并根据所需要的内容 替换params中的参数
代码:AIFaceDetect.py
'''人脸检测与属性分析'''
def AI_facedetect(Path="./face_img/face1.jpg"):# Path="./face1.jpg"request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect"f = open(Path, 'rb')#base64编码后的图片img = base64.b64encode(f.read())params = {"image":img,"image_type":"BASE64","face_field":"faceshape,age,beauty,emotion,gender"}access_token = getAccess("CZ1HCPYGjXvlRVEGKR5XCIWT","xT1CfbqzUa9xFAittlnS8ibc4tL4nTFn")request_url = request_url + "?access_token=" + access_tokenheaders = {'content-type': 'application/json'}response = requests.post(request_url, data=params, headers=headers)if response:print(response.json()['result'],end="\n")print((response.json()['result']['face_list'][0]['location']),\(response.json()['result']['face_list'][0]['face_shape']['type']),\(response.json()['result']['face_list'][0]['beauty']), \(response.json()['result']['face_list'][0]['emotion']['type']), \(response.json()['result']['face_list'][0]['gender']['type']), \(response.json()['result']['face_list'][0]['age']), \(response.json()['result']['face_num']))return(response.json()['result']['face_list'][0]['location']),\(response.json()['result']['face_list'][0]['face_shape']['type']),\(response.json()['result']['face_list'][0]['beauty']), \(response.json()['result']['face_list'][0]['emotion']['type']), \(response.json()['result']['face_list'][0]['gender']['type']), \(response.json()['result']['face_list'][0]['age']), \(response.json()['result']['face_num'])AI_facedetect()
输出的结果:
{'face_num': 1, 'face_list': [{'face_token': 'b4051e5145fa8e0b86c608805a64d80b', 'location': {'left': 423.64, 'top': 669.23, 'width': 245, 'height': 239, 'rotation': -5}, 'face_probability': 1, 'angle': {'yaw': -15.34, 'pitch': 18.32, 'roll': -1.93}, 'face_shape': {'type': 'heart', 'probability': 0.73}, 'age': 23, 'beauty': 66.05, 'emotion': {'type': 'neutral', 'probability': 1}, 'gender': {'type': 'female', 'probability': 1}}]}
{'left': 423.64, 'top': 669.23, 'width': 245, 'height': 239, 'rotation': -5} heart 66.05 neutral female 23 1
将其封装成函数后 便可以在界面中进行调用 响应按钮
槽函数:face_detect.py
def facedet(self): #人脸检测result_face_path="./face_img/result_face1.jpg"self.location,self.face_shape,self.beauty,self.emotion,self.gender,self.age,self.facenum=AI_facedetect(self.imgPath)img2 = cv2.imread(self.imgPath)#绘制矩形# 矩形需要得到左上角和右下角的坐标 即第二和第三个参数print("location:",self.location)print((int(self.location['left']),int(self.location['top'])), (int(self.location['left']+self.location['width']), int(self.location["top"]+self.location["height"])))cv2.rectangle(img2, (int(self.location['left']),int(self.location['top'])),(int(self.location['left']+self.location['width']), int(self.location["top"]+self.location["height"])), color=(0, 0, 255),thickness=6) # 给对角线上的点pointlist[左上,右上,右下,坐下]# cv2.imshow("res",img2)# cv2.waitKey()cv2.imwrite(result_face_path, img2)self.graylabPic.setPixmap(QPixmap(result_face_path).scaled(self.graylabPic.size()))self.lineEditL.setText("人脸:"+str(self.facenum))self.lineEditM.setText("性别:"+str(self.gender))self.lineEditR.setText("年龄:"+str(self.age))self.lineEditDL.setText("脸型:"+str(self.face_shape)) #注意这里要先强制类型转化成stringself.lineEditDM.setText("表情:"+str(self.emotion))self.lineEditDR.setText("魅力值:"+str(self.beauty))
百度智能云的使用——以人脸识别为例相关推荐
- python基于百度智能云实现批量身份证信息识别(附完整代码,可直接使用)
百度智能云配置 一.登录 登录百度智能云,找到卡证文字识别,点击立即使用 地址: https://cloud.baidu.com/product/ocr_cards 二.创建应用 创建一个应用,过程不 ...
- 百度智能云AI接口的植物识别
文章目录 一个10学时的课程作业 一.在百度智能云(https://cloud.baidu.com/)注册账号并实名认证 二.获取接口 1.在用户中心的产品服务中选择图像识别 2.获取accessTo ...
- 【项目实训】基于人脸识别的课堂签到管理系统(python+qt5+sqlite3+百度智能云)
[项目实训]基于人脸识别的课堂签到管理系统(python+qt5+sqlite3+百度智能云) 一.环境介绍 二.签到功能 2.1 启动签到 2.2 结束签到 三.用户组操作 3.1 添加用户组 3. ...
- 智能家居黑科技!首款3D人脸识别智能锁发布 搭载百度智能云函谷物联安全系统...
随着AI在家庭场景中应用的普及与发展,智能锁逐渐成为智能家居的不可或缺的"门面担当",在满足消费者快捷和多样化需求的同时,如何保障家庭安全也成为被重点关注的问题.4月24日,德施曼 ...
- 百度智能云 x 优信 | 最好的二手车VR摄影棚是这样诞生的
去年4月,优信二手车联合百度智能云及百度VR团队各投入40人,秘密在上海嘉定建设二手车VR项目,一举建成全国首个360度的摄影棚.6月项目交付完成之后,双方又组成基建团队,在全国共建设30个摄影棚,上 ...
- 百度智能云人脸采集SDK通过CFCA权威安全测评
当前,黑产攻击手段防不胜防,移动端人脸实名认证环节面临着假体及人脸图片绕过的双重安全风险与挑战.为提升人脸实名认证解决方案的安全性,百度智能云发布了创新炫瞳活体检测增强对于非活体的拦截能力,基于与黑产 ...
- 百度智能云发布『乘风』 端云一体化方案 助力人脸应用10分钟落地
目前人脸技术已在企业办公.智慧社区.金融保险等多领域多场景中落地应用,发展潜力巨大.8月21日,百度大脑开放日"乘风新基建,加速产业智能化升级"专场活动在乌镇召开.会上,基于百度大 ...
- 基于百度智能云api识别验证码
基于百度智能云api识别验证码 通过调用百度智能云api接口进行验证码识别并输出. 使用baidu-aip模块进行模拟client登录,client.basicgeneral()函数识别图片文字并返回 ...
- 2021双十一订单翻倍也不怕,看百度智能云强大OCR赋能快递物流
一年一度的双十一电商"大战"拉开帷幕,剁手党 "买买买",商家配货.消费者抢购的双手不停歇,背后无形的运输网络悄然启动,物流行业的速度战正式打响. 快递业务流程 ...
最新文章
- javascript经典广告代码.rar
- 数据结构-队列详解(类C语言版)
- 宋利:编码既是技术也是艺术
- 一些思维的碎片(二)
- python3连接MSSQL数据库 中文乱码怎么解决?
- TestDriven.NET 2.0——单元测试的好助手(转)
- 01.Matlab文件类型
- 高一下学期计算机考试知识点,高中数学知识点总结
- RateLimiter限流
- (NCRE网络技术)IP地址规划设计技术-知识点
- html的lang属性
- C++ for_each函数
- seo网站优化技巧_新网站的10个SEO技巧
- Variable used in lambda expression should be final or effectively final
- 《c语言入门经典》Ivor Horton第十章练习题4
- Windows指纹登录
- windows垃圾清理脚本
- Mozilla CEO和Firefox OS联合创始人Andreas Gal离职创业
- Unity 碰撞体 composite
- Java实现CSV文件的读写