Views
No views yet
single_mouse_webrtc_project/
├── README.md # 项目主文档
├── API对接文档.md # 详细API对接文档
├── README_Gradio_WebRTC.md # WebRTC技术文档
├── PROJECT_CHECKLIST.md # 部署检查清单
├── requirements_gradio_webrtc.txt # Python依赖文件
├── deploy.sh # 自动部署脚本
├── start_gradio_webrtc.py # 服务启动管理器
├── gradio_webrtc_server.py # Gradio WebRTC服务器
├── gradio_webrtc_api.py # FastAPI REST服务器
├── test_gradio_webrtc_client.py # 完整测试客户端
├── check_model.py # 模型检查脚本
├── inspect_model.py # 模型详细检查脚本
├── create_test_image.py # 测试图像生成脚本
├── test_mouse.jpg # 测试用小鼠图像
└── models/ # 模型文件目录
└── kunin-mice-pose.v0.1.5n.pt # YOLOv8姿态检测模型1# 进入项目目录
2cd single_mouse_webrtc_project
3
4# 运行自动部署脚本
5./deploy.sh1# 1. 创建Python虚拟环境
2conda create -n mouse-webrtc python=3.11
3conda activate mouse-webrtc
4
5# 2. 安装依赖
6pip install -r requirements_gradio_webrtc.txt
7
8# 3. 检查模型
9python check_model.py
10
11# 4. 启动服务
12python start_gradio_webrtc.py1# 运行完整测试套件
2python test_gradio_webrtc_client.py1const ws = new WebSocket('ws://localhost:8765/ws/stream');
2
3ws.onopen = () => console.log('WebSocket连接成功');
4
5// 发送图像帧
6function sendFrame(imageBase64) {
7 const frameData = {
8 image: imageBase64,
9 conf_threshold: 0.3,
10 frame_id: Date.now(),
11 timestamp: Date.now() / 1000
12 };
13 ws.send(JSON.stringify(frameData));
14}
15
16// 接收检测结果
17ws.onmessage = (event) => {
18 const result = JSON.parse(event.data);
19 if (result.success && result.mouse_detected) {
20 console.log('检测到小鼠:', result.keypoints.length, '个关键点');
21 // 处理检测结果...
22 }
23};1// 处理单张图像
2fetch('http://localhost:8765/api/process_frame', {
3 method: 'POST',
4 headers: { 'Content-Type': 'application/json' },
5 body: JSON.stringify({
6 image: imageBase64,
7 conf_threshold: 0.3
8 })
9})
10.then(response => response.json())
11.then(result => {
12 console.log('检测结果:', result);
13});| 索引 | 名称 | 描述 |
|---|---|---|
| 0 | nose | 鼻子 |
| 1 | left_ear | 左耳 |
| 2 | right_ear | 右耳 |
| 3 | torso | 躯干 |
| 4 | left_leg | 左腿 |
| 5 | right_leg | 右腿 |
| 6 | tail_base | 尾巴根部 |
| 7 | tail_tip | 尾巴尖 |
1# 检查模型文件
2ls -la models/
3python check_model.py1# 检查端口使用情况
2lsof -i :7860
3lsof -i :87651# 重新安装依赖
2pip install -r requirements_gradio_webrtc.txt1# 检查CUDA环境
2python -c "import torch; print(torch.cuda.is_available())"1# 启用详细日志
2export LOG_LEVEL=DEBUG
3python start_gradio_webrtc.pyAPI对接文档.md。websockets库连接ws模块