在Widora-OpenWRT上试用百度人脸识别API
来源:互联网 发布:开票软件下载程序 编辑:程序博客网 时间:2024/05/22 03:11
在Widora-OpenWRT平台上试用了一下百度人脸识别API,感觉还可以,人脸识别的准确率还是挺高的。进行人脸识别之前,你必须先注册人员的图片,人脸识别其实是和你先注册的人脸图片进行比对,并给出一个相似度分值,分值达到80就基本可以判定是同一人了。
先注册了3张图片:(用命令 ./face.py -add Linus_Torvalds linus.jpg )
然后分别对另外的三张图片进行识别,结果如下:
下面直接给出python源码
#-------------------------------face.py------------------------------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, urllib, urllib2, json
#------ following SSL set may not be neccessary, depending on your python version
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
data = {}
#------ your BAIDU API access_toke -----------
str_token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
def request_baidu(url,data):
print '//------ start urlencode data ...'
decoded_data = urllib.urlencode(data)
print '//------ start request() ...'
req = urllib2.Request(url, decoded_data)
req.add_header("Content-Type","application/x-www-form-urlencoded")
print '//------ start urlopen() ...It may take a while....'
resp = urllib2.urlopen(req)
content = resp.read()
return content
#--------- detect faces -------
# Example: ./face.py -det julia.jpg
if sys.argv[1]=='-det':
url ='https://aip.baidubce.com/rest/2.0/face/v1/detect?access_token='+ str_token
data['max_face_num'] = 5
data['face_fields'] = "age,beauty,expression,faceshape,gender";
print '//------ start read image data ...'
image_data = open(sys.argv[2],'rb').read()
data['image'] = image_data.encode('base64').replace('\n','')
content=request_baidu(url,data)
json_content=json.loads(content)
num = int(json_content['result_num'])
for i in range(0,num):
print 'Person %d --- age:%s, bueaty:%s, gender:%s' % \
(i,json_content['result'][i]['age'],json_content['result'][i]['beauty'],json_content['result'][i]['gender'])
print 'Location %s' % json_content['result'][i]['location']
#--------- add and register a faces -------
# default: old face data will be replaced.
# Example: ./face.py -add Linus_Torvalds linus.jpg
elif sys.argv[1]=='-add':
url ='https://aip.baidubce.com/rest/2.0/face/v2/faceset/user/add?access_token=' + str_token
#data['uid'] = "Linus_Torvalds"
data['uid'] = sys.argv[2]
data['user_info'] = "father of Linux"
data['group_id'] = "linux_group"
data['action_type'] = "replace"
print '//------ start read image data ...'
image_data = open(sys.argv[3],'rb').read()
data['image'] = image_data.encode('base64').replace('\n','')
content=request_baidu(url,data)
print content
#--------- get info of a registed user -------
# Example: ./face.py -get Linus_Torvalds
elif sys.argv[1]=='-get':
url ='https://aip.baidubce.com/rest/2.0/face/v2/faceset/user/get?access_token=' + str_token
#data['uid'] = "Linus_Torvalds"
data['uid'] = sys.argv[2]
content=request_baidu(url,data)
print content
#------- list all registed users in a specified group -----
# Example: ./face.py -get_users linux_group
elif sys.argv[1]=='-get_users':
url ='https://aip.baidubce.com/rest/2.0/face/v2/faceset/group/getusers?access_token=' + str_token
data['group_id'] = sys.argv[2]
content=request_baidu(url,data)
json_content=json.loads(content)
num = int(json_content['result_num'])
for i in range(0,num):
print '%d: %s --- %s'% (i,json_content['result'][i]['uid'],json_content['result'][i]['user_info'])
#--------- identify a face -------
# Example: ./face.py -id ruhau.jpg
elif sys.argv[1]=='-id':
url ='https://aip.baidubce.com/rest/2.0/face/v2/identify?access_token=' + str_token
data['group_id'] = "linux_group"
data['user_top_num'] = 2
print '//------ start read image data ...'
image_data = open(sys.argv[2],'rb').read()
data['image'] = image_data.encode('base64').replace('\n','')
content=request_baidu(url,data)
json_content=json.loads(content)
num = int(json_content['result_num'])
for i in range(0,num):
print '%d: %s scores: %d group: %s'% \
(i,json_content['result'][i]['uid'],json_content['result'][i]['scores'][0],json_content['result'][i]['group_id'])
else:
print 'command syntax error! check your option'
- 在Widora-OpenWRT上试用百度人脸识别API
- 在Widora上玩MQTT (widora)
- 百度人脸识别API 的使用
- Widora 的Openwrt 系统源代码编译
- 在PowerVR GPU上试用新Vulkan图形处理API
- NetRouter应用教程之Python初接触--基于Widora&Openwrt
- 百度语音识别API初探
- 部署在服务器上的行驶证识别api接口
- 百度人脸识别集成
- 百度人脸识别BFR API效果测试及测试代码
- Java实现调用百度AI开放云平台(人脸识别API)
- 用百度API在地图上画出一只恐龙
- 百度地图API:在RichMarker上使用InfoBox
- 百度地图API:在RichMarker上使用InfoBox
- 在VMWare上跑openwrt
- 在openwrt上安装webcam
- 在AR9331上使用Openwrt
- 在openwrt上运行c
- crontab 定时任务
- 目前安排
- PHP入门(第四弹:WAMPServer自定义端口号)
- 笔记:ORACLE数据库基础学习 第四天
- 经典DP
- 在Widora-OpenWRT上试用百度人脸识别API
- 2017年8月11日提高组T3 难题
- Leetcode-Implement strStr()-Python
- 笔记:ORACLE数据库基础学习 第五天
- Failed to convert from type java.lang.String to type java.util.Date for value解决办法
- 九、再看手写识别问题(内含代码详解及订正)
- RIP(三)【报文控制】
- JAVA:递归和迭代两种方法计算斐波那契数列
- 插入排序--java