Add local Web demo (FastAPI + OpenCV, no browser permission needed)
Browse files- local_web/README.md +68 -0
local_web/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 本地 Web 版 · 手势识别
|
| 2 |
+
|
| 3 |
+
解决"浏览器调摄像头失败 / Hugging Face Static Space 没有 `*.hf.space` 域名"的问题。
|
| 4 |
+
后端(OpenCV)直接打开摄像头,浏览器只显示视频流和交互控制台,**全程无需任何授权**。
|
| 5 |
+
|
| 6 |
+
## 安装
|
| 7 |
+
|
| 8 |
+
```bash
|
| 9 |
+
python3 -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
| 10 |
+
pip install -r requirements.txt
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
## 下载模型
|
| 14 |
+
|
| 15 |
+
`serve.py` 默认在脚本所在目录找 `model_quantized.onnx` + `config.json`,可也用 `--model-dir` 指定:
|
| 16 |
+
|
| 17 |
+
```bash
|
| 18 |
+
# 方式 A:从 HF 仓库下载到本目录
|
| 19 |
+
huggingface-cli download keytic/hand_gestures_onnx \
|
| 20 |
+
--local-dir . \
|
| 21 |
+
--include "model_quantized.onnx" "config.json"
|
| 22 |
+
|
| 23 |
+
# 方式 B:复用 workspace 里的 onnx_pub
|
| 24 |
+
# (直接把 onnx_pub 里的两个文件复制到本目录)
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
相册示例图:默认会自动到 `../static-space/examples/` 找,也可 `--examples-dir` 指定。
|
| 28 |
+
|
| 29 |
+
## 启动
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
python serve.py
|
| 33 |
+
# 浏览器打开 http://localhost:8000
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
常用参数:
|
| 37 |
+
```bash
|
| 38 |
+
python serve.py --camera 0 --interval-ms 300 --port 8000
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## 工作原理
|
| 42 |
+
|
| 43 |
+
```
|
| 44 |
+
[摄像头] ──OpenCV──> [后端推理 (ONNX Runtime)]
|
| 45 |
+
│
|
| 46 |
+
├── 稳定判定 + 触发交互动作(点赞/开关/相册/暂停)
|
| 47 |
+
├── /video MJPEG 视频流 ────────────> 浏览器
|
| 48 |
+
└── /state JSON 状态 (~每 300ms 拉取) ──> 浏览器
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
**浏览器从不调用 `getUserMedia`**,所以没有授权问题、没有跨域、没有 *.hf.space 404。
|
| 52 |
+
|
| 53 |
+
## 手势动作映射
|
| 54 |
+
|
| 55 |
+
| 手势 | 动作 |
|
| 56 |
+
|------|------|
|
| 57 |
+
| 👍 like | 点赞 +1 |
|
| 58 |
+
| 👌 ok | 开关切换 |
|
| 59 |
+
| ✊ fist | 相册上一张 |
|
| 60 |
+
| 🖐️ palm | 相册下一张 |
|
| 61 |
+
| ✌️ peace | 暂停/恢复识别 |
|
| 62 |
+
| 🤘 rock | 重置点赞与日志 |
|
| 63 |
+
|
| 64 |
+
## Linux 系统注意事项
|
| 65 |
+
|
| 66 |
+
- 摄像头权限:当前用户需要在 `video` 组:`sudo usermod -aG video $USER` 然后重登。
|
| 67 |
+
- OpenCV 报错 `Cannot open camera`:检查设备路径(`ls /dev/video*`),必要时换 `--camera 1`。
|
| 68 |
+
- 无图形界面(headless)也能跑,浏览器在另一台机器上访问 `http://<服务器IP>:8000` 即可。
|