1.功能描述:
对于输入的一张图片(可正常解码,且长宽比适宜),检测图片中的所有人手,输出每只手的坐标框、21个骨节点坐标信息。
2.平台接入
具体接入方式比较简单,可以参考我的另一个帖子,这里就不重复了:
http://ai.baidu.com/forum/topic/show/943327
3.调用攻略(Python3)及评测
3.1首先认证授权:
在开始调用任何API之前需要先进行认证授权,具体的说明请参考:
http://ai.baidu.com/docs#/Auth/top
具体Python3代码如下:
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import urllib
import base64
import json
#client_id 为官网获取的AK, client_secret 为官网获取的SK
client_id =【百度云应用的AK】
client_secret =【百度云应用的SK】
#获取token
def get_token():
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + client_id + '&client_secret=' + client_secret
request = urllib.request.Request(host)
request.add_header('Content-Type', 'application/json; charset=UTF-8')
response = urllib.request.urlopen(request)
token_content = response.read()
if token_content:
token_info = json.loads(token_content)
token_key = token_info['access_token']
return token_key
3.2手部关键点识别分析接口调用:
详细说明请参考: https://ai.baidu.com/docs#/Body-API/2757b503
说明的比较清晰,这里就不重复了。
大家需要注意的是:
API访问URL:https://aip.baidubce.com/rest/2.0/image-classify/v1/hand_analysis
图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M。图片的base64编码是不包含图片头的,如(data:image/jpg;base64,),支持图片格式:jpg、bmp、png,最短边至少50px,最长边最大4096px
Python3调用代码如下:
#画出手部识别结果
def draw_hands_point(originfilename,hands,resultfilename,pointsize,pointcolor):
from PIL import Image, ImageDraw
image_origin = Image.open(originfilename)
draw =ImageDraw.Draw(image_origin)
for hand in hands:
for hand_part in hand['hand_parts'].values():
#print(hand_part)
draw.ellipse((hand_part['x']-pointsize,hand_part['y']-pointsize,hand_part['x']+pointsize,hand_part['y']+pointsize),fill = pointcolor)
gesture = hand['location']
draw.rectangle((gesture['left'],gesture['top'],gesture['left']+gesture['width'],gesture['top']+gesture['height']),outline = "red")
image_origin.save(resultfilename, "JPEG")
#手部识别
#filename:原图片名(本地存储包括路径)
def hand_analysis(filename,resultfilename,size,color,pointsize,pointcolor):
request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/hand_analysis"
print(filename)
# 二进制方式打开图片文件
f = open(filename, 'rb')
img = base64.b64encode(f.read())
params = dict()
params['image'] = img
params = urllib.parse.urlencode(params).encode("utf-8")
#params = json.dumps(params).encode('utf-8')
access_token = get_token()
begin = time.perf_counter()
request_url = request_url + "?access_token=" + access_token
request = urllib.request.Request(url=request_url, data=params)
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
response = urllib.request.urlopen(request)
content = response.read()
end = time.perf_counter()
print('处理时长:'+'%.2f'%(end-begin)+'秒')
if content:
#print(content)
content=content.decode('utf-8')
#print(content)
data = json.loads(content)
print('hand_num:',data['hand_num'])
#print(data)
result=data['hand_info']
draw_hands_point(filename,result,resultfilename,pointsize,pointcolor)
4.功能评测:
选用不同的数据对效果进行测试,具体效果如下(以下例子均来自网上):
处理时长:0.44秒
hand_num: 1
处理时长:0.67秒
hand_num: 1
处理时长:0.56秒
hand_num: 1
处理时长:0.86秒
hand_num: 1
可以发现对于单手的情况,速度很快,效果很准确。
处理时长:0.61秒
hand_num: 3
5.测试结论和建议
测试下来,整体识别效果不错。对于手部关键点有较强的识别能力,效果很好,速度也很快。
不过对于比较复杂的图片,如多个手或者背景比较复杂的情况,识别率还有提高的空间,希望后续进一步提高。
建议:
1,可以考虑增加对手势的一些识别,比如握拳,张手等。
2,可以考虑与手势识别的功能进行结合,让客户通过选项选择要返回内内容。
被效果图吸引了么?
进来看教程的,竟然被手吸引了
还可以弄人体穴位图来,大佬们考虑一下这个
语义分割你可以看看 YOLO,fast rcnn, mask rcnn, unet等方面的论文
手势什么的不是图像分类,是语义分割。
视频也是 抽帧+语义分割
视频可以增加对不同帧ROI的bounding box 的位置和大小的对比判断,增加一些新的内容
我看各种关于视频的分类等算法都是抽帧的
这个可以通过抽的细一点来解决啊
question1 五角星和三角形,你用抽帧做的话,如果2帧的点向量速度不够,你怎么判断哩?
现在手势识别和行为识别我觉得都还是在做图像分类。这种很难用这种思想做
不抽帧的话计算量太大
其实深度学习现在很多优化就是为了降低计算要求
这个就是要兼顾效果和效率了
仔细想想用抽帧做 并不能完美做到呢
这个功能用起来感觉很不错
你说的这个需求可以通过抽帧对比手在不同时间的未知,来计算速度,方向,并结合每次抽帧的具体手势来做。
现在几乎所有的视频类的识别都是通过抽帧来做的。
我有个思考了很久的问题,用户任意在三维空间上笔划。假设帧率满足25fps情况下,如何预测用户的手势表达?
例如用户划了个圈,划了个方,划了个向左向右的箭头,向左煽动了一下等未知行为