README.md 8.7 KB
Newer Older
E
Eric.Lee 已提交
1
# HandPose X  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
2
手势 21 个关键点检测  
E
Eric.Lee 已提交
3

4
## 重要更新
E
update  
Eric.Lee 已提交
5 6 7 8 9
### 1)更新数据集 handpose_datasets_v2
* 兼容数据集 handpose_datasets_v1,增加左右手属性"handType": "Left" or "Right",具体参看项目v2数据集示例。
* handpose_datasets_v2 数据总量为 38w+。

### 2)添加 onnx runtime C++ 项目示例支持CPU&GPU,对应项目地址:
10 11
* https://gitcode.net/EricLee/onnx_run
* https://github.com/EricLee2021-72324/onnx_run
E
update  
Eric.Lee 已提交
12 13 14 15
* 添加 onnx 模块,预训练模型中有转好的resnet50-onnx模型,注意:目前不支持rexnetv1

### 3)"dpcas" 项目地址:https://codechina.csdn.net/EricLee/dpcas

16

Eric.Lee2021's avatar
Eric.Lee2021 已提交
17

E
Eric.Lee 已提交
18
## 项目介绍   
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
19
注意:该项目不包括手部检测部分,手部检测项目地址:https://codechina.csdn.net/EricLee/yolo_v3   
E
update  
Eric.Lee 已提交
20
该项目是对手的21个关键点进行检测,示例如下 :    
E
Eric.Lee 已提交
21
* 图片示例:  
Eric.Lee2021's avatar
Eric.Lee2021 已提交
22
![image](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/test.png)    
E
Eric.Lee 已提交
23
* 视频示例:  
Eric.Lee2021's avatar
Eric.Lee2021 已提交
24
![video](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/sample.gif)    
E
update  
Eric.Lee 已提交
25

Eric.Lee2021's avatar
Eric.Lee2021 已提交
26
## Demo小样    
Eric.Lee2021's avatar
Eric.Lee2021 已提交
27 28 29 30
* 示例1 - 按键操作     
  因为考虑到目前没有三维姿态不好识别按键按下三维动作,所以目前采用二维方式。    
  该示例的原理:通过简单的IOU跟踪,对二维目标如手的边界框或是特定手指的较长时间位置稳定性判断确定触发按键动作的时刻,用特定指尖的二维坐标确定触发位置。    
  (注意:目前示例并未添加到工程,后期整理后会进行发布,只是一个样例,同时希望同学们自己尝试写自己基于该项目的小应用。)     
Eric.Lee2021's avatar
Eric.Lee2021 已提交
31
![keyboard](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/keyboard.gif)  
Eric.Lee2021's avatar
Eric.Lee2021 已提交
32

Eric.Lee2021's avatar
Eric.Lee2021 已提交
33 34 35 36 37
* 示例2 - 手势交互:指定区域物体识别      
  该示例的出发点是希望通过手势指定用户想要识别的物体。那么就要选中物体的准确边界框才能达到理想识别效果。如果待识别目标边界框太大会引入背景干扰,太小又会时目标特征不完全。所以希望通过手势指定较准确的目标边界框。因为边界框涉及左上、右下两个二维坐标,所以通过两只手的特定指尖来确定。且触发逻辑与示例1相同。           
  该示例的原理:通过简单的IOU跟踪,对二维目标如手的边界框或是特定手指的较长时间位置稳定性判断确定触发按键动作的时刻,用特定指尖的二维坐标确定触发位置。         
  (注意:目前示例并未添加到工程,后期整理后会进行发布,只是一个样例,同时希望同学们自己尝试写自己基于该项目的小应用。)     
  该示例依赖于另外一个物体识别分类项目。  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
38

Eric.Lee2021's avatar
Eric.Lee2021 已提交
39
![keyboard](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/recognize_obj0.gif)    
Eric.Lee2021's avatar
Eric.Lee2021 已提交
40

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
41
* 以下是对书上狗的图片进行分类识别的样例,同学们可以根据自己对应的物体识别分类需求替换对应的分类识别模型即可。    
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
42

Eric.Lee2021's avatar
Eric.Lee2021 已提交
43
![recoobj_book](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/recobj_book.gif)    
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
44
* [该Demo完整视频](https://www.bilibili.com/video/BV1nb4y1R7Zh/)       
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
45 46

该物体识别分类项目的地址为:  https://codechina.csdn.net/EricLee/classification     
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
47

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
48
* 示例3 - 静态手势     
Eric.Lee2021's avatar
Eric.Lee2021 已提交
49
  通过手关键点的二维角度约束关系定义静态手势。  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
50
  示例中手势包括:fist five gun love one six three thumbup yeah    
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
51 52
  目前该示例由于静态手势数据集的限制,目前用手骨骼的二维角度约束定义静态手势,原理如下图,计算向量AC和DE的角度,它们之间的角度大于某一个角度阈值(经验值)定义为弯曲,小于摸一个阈值(经验值)为伸直。    
  注:这种静态手势识别的方法具有局限性,有条件还是通过模型训练的方法进行静态手势识别。   
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
53

Eric.Lee2021's avatar
Eric.Lee2021 已提交
54
![gs](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/gest.jpg)     
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
55

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
56
  视频示例如下图:   
Eric.Lee2021's avatar
Eric.Lee2021 已提交
57
![gesture](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/gesture.gif)     
Eric.Lee2021's avatar
Eric.Lee2021 已提交
58

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
59 60 61
* 示例4 - 静态手势交互(识别)      
  通过手关键点的二维角度约束关系定义静态手势。     
  该项目通过手势操作选择分类识别区域或是ocr识别区域,送入分类识别网络或是第三方web识别服务,亦或是检索数据库等应用。   
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
62

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
63 64
  原理:通过二维约束获得静态手势,该示例是通过 食指伸直(one) 和 握拳(fist)分别代表范围选择和清空选择区域。    
  建议最好还是通过分类模型做静态手势识别鲁棒和准确高,目前局限于静态手势训练集的问题用二维约束关系定义静态手势替代。    
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
65

Eric.Lee2021's avatar
Eric.Lee2021 已提交
66
![ocrreco](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/ocrreco.gif)       
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
67
* [该Demo完整视频](https://www.bilibili.com/video/BV1Bb4y1R7sd/)       
Eric.Lee2021's avatar
Eric.Lee2021 已提交
68

E
Eric.Lee 已提交
69
## 项目配置  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
70
### 1、软件  
E
update  
Eric.Lee 已提交
71
* 作者开发环境:  
E
Eric.Lee 已提交
72 73
* Python 3.7  
* PyTorch >= 1.5.1  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
74
* opencv-python  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
75 76
### 2、硬件  
* 普通USB彩色(RGB)网络摄像头    
E
Eric.Lee 已提交
77

E
Eric.Lee 已提交
78
## 数据集   
E
Eric.Lee 已提交
79
### 1)handpose_datasets_v1
E
Eric.Lee 已提交
80
该数据集包括网络图片及数据集<<Large-scale Multiview 3D Hand Pose Dataset>>筛选动作重复度低的部分图片,进行制作(如有侵权请联系删除),共49062个样本。         
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
81
<<Large-scale Multiview 3D Hand Pose Dataset>>数据集,其官网地址 http://www.rovit.ua.es/dataset/mhpdataset/       
E
Eric.Lee 已提交
82
感谢《Large-scale Multiview 3D Hand Pose Dataset》数据集贡献者:Francisco Gomez-Donoso, Sergio Orts-Escolano, and Miguel Cazorla. "Large-scale Multiview 3D Hand Pose Dataset". ArXiv e-prints 1707.03742, July 2017.    
E
Eric.Lee 已提交
83

E
Eric.Lee 已提交
84
* 标注文件示例:   
Eric.Lee2021's avatar
Eric.Lee2021 已提交
85
![label](https://codechina.csdn.net/EricLee/handpose_x/-/raw/master/samples/label.png)   
E
Eric.Lee 已提交
86

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
87 88
* [该项目用到的制作数据集下载地址(百度网盘 Password: ara8 )](https://pan.baidu.com/s/1KY7lAFXBTfrFHlApxTY8NA)   

E
Eric.Lee 已提交
89
* 如果使用该数据集并发布相关项目或网络资源文章等,请讲述其数据集的出处 "https://codechina.csdn.net/EricLee/handpose_x"    
E
Eric.Lee 已提交
90
* 数据集读取脚本为:read_datasets.py,并需要相应更改脚本中的数据集路径。  
E
Eric.Lee 已提交
91

E
Eric.Lee 已提交
92
### 2)handpose_datasets_v2
E
update  
Eric.Lee 已提交
93 94 95 96 97 98 99 100 101 102
* 兼容数据集 handpose_datasets_v1,增加左右手属性"handType": "Left" or "Right",具体参看项目v2数据集示例。
* handpose_datasets_v2 数据总量为 38w+。
```
注意:
 1> 该数据集包括网络图片进行制作(如有侵权请联系删除),
 2> 项目使用该数据集请注明出处:
     项目:https://gitcode.net/EricLee/handpose_x
     作者:Eric.Lee
```
* handpose_datasets_v2 例子如下图:
E
Eric.Lee 已提交
103 104 105 106
![v2_sample](samples/v2.png)   
* 数据集读取脚本为:read_datasets.py,并需要相应更改脚本中的数据集路径。
* [该项目用到的制作数据集下载地址(百度网盘 Password: 1vqw )](https://pan.baidu.com/s/1T5vdiCN9VPv2ooX_PiMukg)  

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
107
## 模型   
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
108
### 1、目前支持的模型 (backbone)
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
109

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
110 111 112
- [x] resnet18 & resnet34 & resnet50 & resnet101
- [x] squeezenet1_0 & squeezenet1_1
- [x] ShuffleNet & ShuffleNetV2
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
113
- [x] MobileNetV2
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
114
- [x] rexnetv1
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
115
- [x] shufflenet_v2_x1_5 ,shufflenet_v2_x1_0 , shufflenet_v2_x2_0 (torchvision 版本)
E
Eric.Lee 已提交
116

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
117
### 2、预训练模型   
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
118

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
119
* [预训练模型下载地址(百度网盘 Password: 99f3 )](https://pan.baidu.com/s/1Ur6Ikp31XGEuA3hQjYzwIw)        
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
120

E
Eric.Lee 已提交
121 122 123

## 项目使用方法  
### 模型训练  
Eric.Lee2021's avatar
Eric.Lee2021 已提交
124 125 126 127 128
* 根目录下运行命令: python train.py       (注意脚本内相关参数配置 )   

### 模型推理  
* 根目录下运行命令: python inference.py        (注意脚本内相关参数配置 )   

L
lixiang 已提交
129 130 131
### onnx使用  
* step1: 设定相关配置包括模型类型和模型参数路径,根目录下运行命令: python model2onnx.py        (注意脚本内相关参数配置 )
* step2: 设定onnx模型路径,根目录下运行命令: python onnx_inference.py   (注意脚本内相关参数配置 )  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
132
* 建议    
Eric.Lee2021's avatar
Eric.Lee2021 已提交
133 134
```

Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
135 136 137 138
检测手bbox后,进行以下的预处理,crop手图片送入手关键点模型进行推理,   
可以参考 hand_data_iter/datasets.py,数据增强的样本预处理代码部分,   
关键代码如下:     
  img 为原图  ,np为numpy  
Eric.Lee2021's avatar
Eric.Lee2021 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  x_min,y_min,x_max,y_max,score = bbox  
  w_ = max(abs(x_max-x_min),abs(y_max-y_min))  

  w_ = w_*1.1  

  x_mid = (x_max+x_min)/2  
  y_mid = (y_max+y_min)/2  

  x1,y1,x2,y2 = int(x_mid-w_/2),int(y_mid-w_/2),int(x_mid+w_/2),int(y_mid+w_/2)  

  x1 = np.clip(x1,0,img.shape[1]-1)  
  x2 = np.clip(x2,0,img.shape[1]-1)  

  y1 = np.clip(y1,0,img.shape[0]-1)  
  y2 = np.clip(y2,0,img.shape[0]-1)  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
154

Eric.Lee2021's avatar
Eric.Lee2021 已提交
155
```
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
156 157 158

## 联系方式 (Contact)  
* E-mails: 305141918@qq.com   
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
159 160

## 特别感谢
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
161
* 特别感谢神力社群的朋友对 " HandPose X " 项目进行二次开发,推进了该算法模型能够在实际应用中加速落地。  
Eric.Lee2021's avatar
update  
Eric.Lee2021 已提交
162
* http://manaai.cn/aicodes_detail3.html?id=75