OpenVINO对象检测MCP(HTTP服务器)
这是一个外部HTTP MCP服务器,使用YOLOv11模型提供对象检测功能,该模型使用Intel OpenVINO进行了优化,以实现高效推理。
特性
- YOLOv11目标检测:使用多种模型尺寸进行最先进的物体检测
- OpenVINO优化:Intel CPU、GPU和VPU上的硬件加速推理
- HTTP传输:作为HTTP服务器运行,用于外部服务部署
- 构建时模型转换:Docker镜像在构建过程中预转换所有模型(运行时没有PyTorch/CUDA)
- 自动模型下载:本地开发在首次使用时自动下载模型
- 灵活输入:通过文件路径或base64编码字符串接受图像
- 视觉输出:返回结构化检测数据和带注释的叠加图像
- COCO类:检测80个不同的对象类别
- 优化的Docker镜像:预转换模型的图像缩小50-60%
安装
pip install -r requirements.txt运行服务器
HTTP服务器(默认)
python main.py
# Server starts on http://127.0.0.1:8006/mcp自定义端口/主机
python main.py --host 0.0.0.0 --port 8080苏格兰和南方能源公司运输
python main.py --sse --port 8006STDIO传输(用于本地MCP)
python main.py --stdio配置
将以下内容添加到MCP配置中以使用此服务器:
{
"openvino-object-detection": {
"enabled": true,
"url": "http://127.0.0.1:8006/mcp",
"transport": "http",
"groups": ["users"],
"description": "Object detection using YOLOv11 with OpenVINO optimization",
"short_description": "OpenVINO YOLOv11 object detection"
}
}可用工具
1. detect_objects
对图像文件执行对象检测。
参数:
image_path(str):输入图像文件的路径model_name(str,可选):YOLO型号变体(默认:“yolo11n”)confidence_threshold(浮动,可选):最小置信度得分(默认值:0.25)iou_threshold(浮动,可选):NMS的IoU阈值(默认值:0.45)device(str,可选):OpenVINO设备-“自动”、“CPU”、“GPU”(默认:“自动”)output_path(str,可选):保存带注释的输出图像的路径
2. detect_objects_base64
对base64编码的图像执行对象检测。
参数:
image_base64(str):Base64编码图像字符串model_name(str,可选):YOLO型号变体(默认:“yolo11n”)confidence_threshold(浮动,可选):最小置信度得分(默认值:0.25)iou_threshold(浮动,可选):NMS的IoU阈值(默认值:0.45)device(str,可选):OpenVINO设备(默认:“AUTO”)
3. list_available_models
获取有关可用YOLO型号的信息。
4. get_class_labels
获取80个可检测的COCO对象类的列表。
响应格式
{
"results": {
"detections": [
{
"class_id": 0,
"class_name": "person",
"confidence": 0.92,
"bbox": {
"x1": 100, "y1": 50,
"x2": 300, "y2": 400,
"width": 200, "height": 350
}
}
],
"detection_count": 1,
"image_size": {"width": 640, "height": 480},
"overlay_base64": "base64_encoded_png..."
},
"meta_data": {
"model_name": "yolo11n",
"device": "AUTO",
"inference_time_ms": 45.2,
"elapsed_ms": 120.5,
"is_error": false
}
}支持的型号
| 型号 | 参数 | 速度 | 精度 | 用例 |
|---|---|---|---|---|
| yolo11n | ~2.6M | 最快 | 良好 | 实时,嵌入式 |
| yolo11s | ~9.4M | 快速 | 更好 | 通用 |
| 约洛11米 | ~20.1米 | 中等 | 高 | 平衡 |
| yolo11l | ~25.3M | 较慢 | 非常高 | 精度高 |
| yolo11x | ~56.9M | 最慢 | 最高 | 最高精度 |
支持的对象类
这些模型检测了80个COCO类别,包括:
- 人们:人
- 车辆:自行车、汽车、摩托车、飞机、公共汽车、火车、卡车、船
- 动物:鸟、猫、狗、马、绵羊、牛、大象、熊、斑马、长颈鹿
- 运动:飞盘、滑雪板、单板滑雪板、运动球、风筝、棒球棒/手套、滑板、冲浪板、网球拍
- 食物:香蕉、苹果、三明治、橙子、西兰花、胡萝卜、热狗、披萨、甜甜圈、蛋糕
- 家具:椅子、沙发、床、餐桌、卫生间
- 电子学:电视、笔记本电脑、鼠标、遥控器、键盘、手机
- 还有更多。..
Docker部署
有四种容器可供选择:
| 变量 | 基础图像 | 模型转换 | 启动时间 | 图像大小 |
|---|---|---|---|---|
ubuntu | Ubuntu 24.04 | 构建时间 | ~2s | 更小 |
rhel | RHEL UBI 9 | 构建时间 | ~2s | 更小 |
ubuntu-runtime | Ubuntu 24.04 | 首次启动 | ~40s | 更大 |
rhel-runtime | RHEL UBI 9 | 首次启动 | ~40s | 更大 |
构建所有容器
# Build all 4 variants (supports both docker and podman)
./create_containers.sh
# Build specific variants
./create_containers.sh --ubuntu # Ubuntu pre-converted only
./create_containers.sh --rhel # RHEL pre-converted only
./create_containers.sh --ubuntu-runtime # Ubuntu runtime only
./create_containers.sh --rhel-runtime # RHEL runtime only
# Build without cache
./create_containers.sh --no-cache运行容器
# Pre-converted variants (faster startup, recommended)
docker run -d -p 8006:8006 openvino-detection:ubuntu
docker run -d -p 8006:8006 openvino-detection:rhel
# Runtime variants (convert models on first startup, needs volume for caching)
docker run -d -p 8006:8006 -v openvino-models:/app/models openvino-detection:ubuntu-runtime
docker run -d -p 8006:8006 -v openvino-models:/app/models openvino-detection:rhel-runtime测试推断
# Run inference test (uses test.png by default)
python test_inference.py
# Test with suffix for each container variant
python test_inference.py --suffix ubuntu
python test_inference.py --suffix rhel
# Custom image and output
python test_inference.py --image myimage.jpg --output result.png
# Verbose output
python test_inference.py --verbose测试输出另存为 test_output_.png 覆盖检测边界框。
业绩说明
- 第一次运行将下载YOLO型号(~10-50MB,取决于变体)
- OpenVINO自动选择最佳可用硬件
- 模型在首次加载后被缓存,以便更快地进行后续推理
- 对于GPU加速,请确保安装了OpenVINO GPU插件
许可证
此MCP使用:
- Ultralytics YOLO -AGPL-3.0
- OpenVINO -Apache 2.0
