一、结果保存与输出全景图
mermaid
graph TD
A[检测结果] --> B[文本文件]
A --> C[图像标注]
A --> D[JSON文件]
A --> E[视频输出]
A --> F[实时显示]
二、核心代码实现
1. 基础结果保存
python
from ultralytics import YOLO
import cv2
import json
model = YOLO('yolov8s.pt')
results = model.predict('input.jpg')
# 保存标注图像
annotated_img = results[0].plot() # 自动生成标注图
cv2.imwrite('output.jpg', annotated_img)
# 保存文本信息
with open('results.txt', 'w') as f:
for box in results[0].boxes:
f.write(f"{model.names[int(box.cls)]} {box.conf:.2f} {box.xyxy[0].tolist()}\n")
# 保存JSON格式
results_json = {
"filename": "input.jpg",
"detections": [
{
"class": model.na