博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
阿里云 人脸识别 测试
阅读量:4200 次
发布时间:2019-05-26

本文共 3782 字,大约阅读时间需要 12 分钟。

阿里云 人脸识别 测试

1.使用阿里云平台提供的接口直接测试人脸识别功能

  • 人脸属性识别请求地址:
  • 人脸检测定位请求地址:

参考代码:python2.x

#!/usr/bin/python# -*- coding:utf-8 -*-from urlparse import urlparseimport datetimeimport base64import hmacimport hashlibimport jsonimport urllib2def get_current_date():    date = datetime.datetime.strftime(datetime.datetime.utcnow(), "%a, %d %b %Y %H:%M:%S GMT")    return datedef to_md5_base64(strBody):    hash = hashlib.md5()    hash.update(body)    return hash.digest().encode('base64').strip()def to_sha1_base64(stringToSign, secret):    hmacsha1 = hmac.new(secret, stringToSign, hashlib.sha1)    return base64.b64encode(hmacsha1.digest())ak_id = '添加阿里云AccessKey ID'ak_secret = '添加阿里云Access Key Secret'options = {
'url': 'https://dtplus-cn-shanghai.data.aliyuncs.com/face/attribute', 'method': 'POST', 'body': json.dumps({
"type": 0, "image_url": "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1550729205230&di=4e533df8440316eaf5c237f6fdbcb40a&imgtype=0&src=http%3A%2F%2Fimg2.cache.netease.com%2Fphoto%2F0026%2F2017-04-22%2FCILFTVLK78LH0026.jpg" }, separators=(',', ':')), 'headers': {
'accept': 'application/json', 'content-type': 'application/json', 'date': get_current_date(), 'authorization': '' }}body = ''if 'body' in options: body = options['body']print bodybodymd5 = ''if not body == '': bodymd5 = to_md5_base64(body)print bodymd5urlPath = urlparse(options['url'])if urlPath.query != '': urlPath = urlPath.path + "?" + urlPath.queryelse: urlPath = urlPath.pathstringToSign = options['method'] + '\n' + options['headers']['accept'] + '\n' + bodymd5 + '\n' + options['headers'][ 'content-type'] + '\n' + options['headers']['date'] + '\n' + urlPathsignature = to_sha1_base64(stringToSign, ak_secret)print stringToSignauthHeader = 'Dataplus ' + ak_id + ':' + signatureoptions['headers']['authorization'] = authHeaderprint authHeaderrequest = Nonemethod = options['method']url = options['url']print methodprint urlif 'GET' == method or 'DELETE' == method: request = urllib2.Request(url)elif 'POST' == method or 'PUT' == method: request = urllib2.Request(url, body)request.get_method = lambda: methodfor key, value in options['headers'].items(): request.add_header(key, value)try: conn = urllib2.urlopen(request) response = conn.read() print responseexcept urllib2.HTTPError, e: print e.read() raise SystemExit(e)

2.人脸识别返回结果

{
"face_num":1, "face_rect":[ 248, 96, 98, 133 ], "face_prob":[ 1 ], "pose":[ -16.07172966003418, -8.95702838897705, 1.9855666160583496 ], "landmark_num":105, "landmark":[ 247.61978149414062, 137.2036590576172, 268.0321350097656, 139.6984405517578, 135.26028442382812, # ... ... 略去n行数据 177.718994140625, 263.8021240234375, 211.8135986328125, 309.4313049316406, 223.700439453125 ], "iris":[ 266.2425842285156, 150.38868713378906, 4.3046369552612305, 309.6331481933594, 154.08685302734375, 4.3046369552612305 ], "gender":[ 0 ], "age":[ 23 ], "expression":[ 1 ], "glass":[ 0 ], "dense_fea_len":1024, "dense_fea":[ -0.025663359090685844, 0.023277662694454193, -0.0033915694802999496, -0.029405198991298676, 0.03825557976961136, # ... ... 略去n行数据 0.002641384955495596, -0.029730748385190964, -0.0018590112449601293, -0.04892149567604065, 0.03814288601279259, 0.0002941368438769132 ], "errno":0, "request_id":"11e53710-7b6e-48cd-86e4-963e0e48fda9"}

3.参考

转载地址:http://grfli.baihongyu.com/

你可能感兴趣的文章
如何给分类增加一个属性(后台)
查看>>
linux设置环境变量 临时设置 和 永久设置
查看>>
检查网站在世界各地的打开速度
查看>>
jquery 向上(顶部),向下(底部)滑动
查看>>
seo
查看>>
10个出色的NoSQL数据库
查看>>
MySQL: InnoDB 还是 MyISAM?
查看>>
MySQL性能优化的最佳20+条经验
查看>>
SQL语言的组成部分 ddl dcl dml
查看>>
mysql数据库从库同步延迟的问题
查看>>
1.mysql数据库主从复制部署笔记
查看>>
mysql数据库主从同步的问题解决方法
查看>>
mysql 配置 - on xFanxcy.com
查看>>
MySQL数据库高并发优化配置
查看>>
mysql一: 索引优化
查看>>
测试人员,今天再不懂BDD就晚了!
查看>>
35岁后还被职场青睐的人,都做了这几件事
查看>>
全链路压测那点事(一)
查看>>
阿里巴巴开源性能监控神器Arthas初体验
查看>>
使用猴子测试工具(7)
查看>>