Dish_Recognition/central_server/README.md

77 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 总服务器中心 API
给**总服务器**单独用的服务:收工位机图片、提供图片 URL、接收识别结果。
不依赖相机、YOLO、客户端界面。把整个 `central_server` 文件夹拷到总机即可。
## 快速启动
Windows:
1. 安装 Python 3.10+(标准库即可,无需 torch)
2. 双击 `start.bat`,或在本目录执行:
```bat
python start.py
```
也可在项目根目录:
```bat
python -m central_server
```
默认地址:`http://本机IP:9000`
浏览器打开:`http://127.0.0.1:9000/api/health` 能看到 `"status": "up"` 即成功。
## 配置
1. 复制 `env.example` 为 `.env`
2. 把 `DISH_MEDIA_PUBLIC_BASE` 改成工位机能访问的地址,例如:
```
DISH_MEDIA_PUBLIC_BASE=http://192.168.1.10:9000/media
DISH_API_HOST=0.0.0.0
DISH_API_PORT=9000
DISH_API_TOKEN=你的密钥
```
防火墙放行 9000 端口。
## 接口
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/api/health` | 探活 |
| POST | `/api/dish/media/upload` | 上传图片,返回 `url` |
| GET | `/media/...` | 访问已上传图片 |
| POST | `/api/dish/recognize/result` | 上报识别结果(字段为 URL) |
| GET | `/api/dish/recognize/records` | 最近结果列表 |
数据目录(自动创建):
```
central_server/data/media/ 图片
central_server/data/results/ 识别 JSON
```
## 工位机怎么连
工位机客户端设置(或环境变量):
```
DISH_RESULT_API_MOCK=0
DISH_RESULT_API_URL=http://总服务器IP:9000/api/dish/recognize/result
DISH_MEDIA_UPLOAD_URL=http://总服务器IP:9000/api/dish/media/upload
DISH_MEDIA_PUBLIC_BASE=http://总服务器IP:9000/media
DISH_API_TOKEN=与总服务器相同(若启用)
```
流程:工位机先传图,再上报 JSON。业务系统只访问总服务器,不直连工位。
## 生产建议
- 前面加 Nginx,做 HTTPS 反代
- `DISH_MEDIA_PUBLIC_BASE` 写成 `https://域名/media`
- 图片量大时把 `data/media` 挂到磁盘或 OSS,接口不用改