Skip to content

WebSocket 协议

低延迟实时目标检测流式协议。


📋 概述

WebSocket 连接为实时视频分析提供最低延迟。

端点: ws://localhost:8000/ws


🔌 连接

URL 格式

ws://{host}/ws?model={model_id}&conf={confidence}&iou={iou}

连接示例

javascript
const ws = new WebSocket('ws://localhost:8000/ws?model=yolov8n.pt&conf=0.25');

📤 客户端 → 服务器消息

二进制图像帧

发送 JPEG 编码的图像作为二进制消息:

javascript
canvas.toBlob((blob) => {
  ws.send(blob);
}, 'image/jpeg', 0.85);

配置更新

javascript
ws.send(JSON.stringify({
  type: 'config',
  conf: 0.5,
  iou: 0.4,
  max_det: 100
}));

📥 服务器 → 客户端消息

检测结果

json
{
  "type": "result",
  "data": {
    "width": 640,
    "height": 480,
    "detections": [
      {
        "bbox": [100.5, 200.3, 250.8, 450.2],
        "score": 0.89,
        "label": "person"
      }
    ],
    "inference_time": 12.5
  }
}

🔗 相关文档

Released under the MIT License.