# Gesture detection
tldr; Glorified Bluetooth macro keyboard with machine learning (TensorFlow Lite for Microcontrollers) running on an ESP32.
## Main features
- Capacitive touch pad for drawing gestures on that maps to actions on the computer.
- Capacitive touch bar for volume control.
- 11 Buttons for generic control.
- Optional AutoHotkey for programatical control exactly what shall happen when keys are pressed or a gesture is drawn.
- Small OLED display for various info such as crypto prices, remote Bluetooth status, local IP and gesture prediction debug info.
- BLE HID to connect to a computer and act as a keyboard.
- Such very RGB.
![training](.github/both.JPG)
![training](.github/top.JPG)
![training](.github/side.JPG)
<p float="left">
<img src=".github/day.jpg" width="49%" />
<img src=".github/rgb.jpg" width="49%" />
</p>
![training](.github/caps.JPG)
![training](.github/demo.gif)
### How it works
The switch presses and the touchpad gestures will end up being sent as a keyboard shortcut. This CAN be enough for some use cases, but it gets really powerful when coupled together with something AutoHotkey scripts running on the computer.
**Current AutoHotkey script works as following**
On the computer focus one window and then hold down one of SWITCH_1-10 for 2s. This will connect this key to that specific window. When clicking the key it will focus window if not in focus, and if in focus minimize it.
**Gestures are mapped as following**
| Gesture | Action | How to remember
| ------------- |:-------------|:-------------|
|ARROW_RIGHT | Media key next track | > as in next
|ARROW_UP | git push current branch | ʌ as in away/push
|C_GESTURE | Display all the COM ports on the computer as a notification | 'C' as in COM Port
|LINE_DOWN_GESTURE | git log | 'l' as in log
|LINE_HORIZONTAL_GESTURE | git diff |
|S_GESTURE | git status | 'S' as in status
|ARROW_DOWN | git fetch and git pull current branch | 'V' as in pull
|... | whatever | ...
Note the commands involving git above will also focus the git terminal window before executing the action. For this to work SWITCH_2 is expected to be mapped with a git terminal window. For more detailed info about the actions look in
[`hotkeys/hotkey_handler.ahk`](hotkeys/hotkey_handler.ahk)
#### SWITCH_11
Is special key and used for enable Bluetooth pairing (hold down for 5s) and moving through the different "menus" on the OLED screen.
## Compiling ESP32 code
Follow instruction on [https://github.com/espressif/esp-idf](https://github.com/espressif/esp-idf) to set up the esp-idf, then just run `idf.py build` or use the [VSCode extension](https://github.com/espressif/vscode-esp-idf-extension). Tested with esp-idf 4.2.
## Tensorflow gesture/shape detection
Tensorflow Lite is used to recognize what is being drawn on the touchpad. There are already some shapes/gestures training data collected by me and is found in the `/training/train_data` folder and a pre trained model using those is what is being used by default. The trackpad outputs x, y coordinates in the range [0,1792], coordinates collected between touch start and touch release are then converted into a 28x28 2D matrix which is used as input to TensorFlow.
**Example how simple it is to add a new gesture**
![training](.github/done.gif)
[Higher res video here](https://youtu.be/cg1-SUCJ2Vs)
### Gather train data
First you need to enter training mode on the macro keybord by holding down SWITCH_11 while plugging in power. In training mode the device pretty much just pipes the raw data from the trackpad over UART as a string with this format: `[x1, y1, x2, y2,...]\n`. Then go to the `/training` folder. For each new gesture `collect_train_data.py` needs to run twice, first to collect train data and then to collect test data. For current number of gestures (7) about 150 train samples and about 45 test samples seems to be enough to get very good predictions.
python collect_train_data.py --port COMX --gesture_name v_shape
python collect_train_data.py --port COMX --gesture_name v_shape --test_data
After each drawn gesture a plot of the input data will be shown, if it looks bad because you made a misstake, then just press ENTER in the console and the last sample will be removed from the data. Press `ctrl+c` when done.
### Training the model
When collection of data is finished run `python train_model.py --center_gesture` it will take about 30s depending on computer. It will pick up all train data in the `train_data` folder, so remove any data for unwanted gestures. This script will generate a `gesture_model_tflite.c` and `gesture_model_tflite.h` files containing the TF Lite model that can be imported by embedded TF Lite. The `gesture_model_tflite.h` file is also generated from the Python code and contains various information such as the map between predictions (int) and their meaning, if `--center_gesture` was used when training, etc. All output from the `train_model.py` will be put in a folder `training/output`. When compiling the embedded code the generated `.c` and `.h` files are automatically copied into the C code directory so latest model will always be compiled.
#### `--center_gesture`
Option to center the gesture in the input matrix, this will help when the training data is drawn at a specific location on the trackpad, but you want it to be recognized anywhere. This option will remove functionality to have for example two line down gestures, one at the right side and one at the left side of the trackpad as this option will move both gestures to the center. For this to work the same change is needed on target before inputing the drawn gesture to the embedded model. This is handled automatically as this is added into the `gesture_model_tflite.h` file and handled accordingly in embedded code.
**Study the graphs to see how well the model performed on test data.**
![training](.github/training.png)
### Testing/verifying the model
Before moving the model into the microcontroller it's a good idea to test it first. First make sure the device is in training mode as described before, then test the model by running `python test_model.py --port COMX --center_gesture` and watch the predictions show as you draw on the trackpad.
## AutoHotkey setup
- Install Auto Hotkey from https://www.autohotkey.com/
- Right click on the `hotkeys/hotkey_handler.ahk` -> compile
- Now you will get an .exe file, right click on this and create a shortcut
- To auto start with Windows type `Windows key + r`
- Run `shell:startup` and paste the `hotkey_handler.exe - Shortcut` into the opened folder.
- Done
## CAD model
Full Fusion 360 project is found in `CAD` folder.
## Trill sensors
Bought from their Kickstarter in 2019, but can be bought today from [here now](https://bela.io/products/trill/)
没有合适的资源?快使用搜索试试~ 我知道了~
带有在ESP32上运行的机器学习(用于微控制器的TensorFlowLite)的美化蓝牙宏键盘_C_Python_下载.zip
共297个文件
h:142个
cc:91个
c:13个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 33 浏览量
2023-05-01
01:08:14
上传
评论
收藏 33.58MB ZIP 举报
温馨提示
带有在ESP32上运行的机器学习(用于微控制器的TensorFlowLite)的美化蓝牙宏键盘_C_Python_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
带有在ESP32上运行的机器学习(用于微控制器的TensorFlowLite)的美化蓝牙宏键盘_C_Python_下载.zip (297个子文件)
hotkey_handler.ahk 6KB
hid_device_le_prf.c 42KB
main.c 11KB
ble_hid.c 9KB
menu.c 7KB
common.c 7KB
led_strip_rmt_ws2812.c 6KB
display.c 5KB
keypress_input.c 5KB
key_backlight.c 5KB
esp_hidd_prf_api.c 4KB
hid_dev.c 4KB
market_data.c 4KB
keymap_config.c 2KB
gesture_model_tflite.cc 210KB
gesture_model_tflite.cc 210KB
flatbuffer_conversions.cc 84KB
micro_allocator.cc 47KB
test_helpers.cc 41KB
detection_postprocess.cc 34KB
comparisons.cc 30KB
kernel_util.cc 20KB
svdf_common.cc 18KB
greedy_memory_planner.cc 16KB
quantization_util.cc 15KB
micro_interpreter.cc 15KB
reduce.cc 14KB
transpose_conv.cc 11KB
activations.cc 11KB
add.cc 10KB
pooling.cc 10KB
recording_micro_allocator.cc 10KB
micro_string.cc 10KB
sub.cc 10KB
pad.cc 10KB
concatenation.cc 10KB
mul.cc 9KB
depthwise_conv_common.cc 8KB
conv_common.cc 8KB
add_n.cc 8KB
strided_slice.cc 8KB
quantize_common.cc 8KB
circular_buffer.cc 7KB
elementwise.cc 7KB
prelu.cc 7KB
softmax_common.cc 6KB
kernel_runner.cc 6KB
tanh.cc 6KB
l2norm.cc 6KB
leaky_relu.cc 6KB
l2_pool_2d.cc 6KB
logistic.cc 6KB
elu.cc 5KB
dequantize.cc 5KB
memory_helpers.cc 5KB
touchpad_sensor.cc 5KB
simple_memory_allocator.cc 5KB
hard_swish.cc 5KB
tf_gesture_predictor.cc 5KB
fully_connected.cc 5KB
expand_dims.cc 5KB
maximum_minimum.cc 5KB
space_to_batch_nd.cc 5KB
arg_min_max.cc 5KB
split_v.cc 4KB
resize_nearest_neighbor.cc 4KB
split.cc 4KB
floor_div.cc 4KB
fill.cc 4KB
batch_to_space_nd.cc 4KB
reshape.cc 4KB
conv.cc 4KB
depthwise_conv.cc 4KB
squeeze.cc 4KB
pack.cc 4KB
unpack.cc 4KB
logical.cc 4KB
softmax.cc 3KB
fully_connected_common.cc 3KB
cumsum.cc 3KB
svdf.cc 3KB
cast.cc 3KB
zeros_like.cc 3KB
exp.cc 3KB
recording_simple_memory_allocator.cc 3KB
round.cc 3KB
ceil.cc 3KB
kernel_util.cc 3KB
micro_utils.cc 3KB
schema_utils.cc 3KB
op_resolver.cc 3KB
debug_log.cc 2KB
shape.cc 2KB
micro_time.cc 2KB
neg.cc 2KB
all_ops_resolver.cc 2KB
linear_memory_planner.cc 2KB
micro_error_reporter.cc 2KB
floor.cc 2KB
micro_profiler.cc 2KB
共 297 条
- 1
- 2
- 3
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- n.cpp
- jdk-8u411-windows-x64下载安装可用
- vgg模型-图像分类算法对水果识别-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- vgg模型-python语言pytorch框架训练识别化妆品分类-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- shufflenet模型-基于人工智能的卷积网络训练识别狗的表情-不含数据集图片-含逐行注释和说明文档.zip
- shufflenet模型-python语言pytorch框架训练识别张嘴闭嘴-不含数据集图片-含逐行注释和说明文档.zip
- resnet模型-基于人工智能的卷积网络训练识别面部表情识别-不含数据集图片-含逐行注释和说明文档
- resnet模型-python语言pytorch框架训练识别香蕉品质-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功