This commit is contained in:
2025-09-03 16:22:21 +08:00
parent b7773f5f00
commit d83923d06b
5 changed files with 211 additions and 342 deletions

View File

@ -1,6 +1,5 @@
from ultralytics import YOLO
import cv2
from logger_config import logger
class ViolationDetector:
"""
@ -13,9 +12,9 @@ class ViolationDetector:
Args:
model_path (str): YOLO .pt模型的路径。
"""
logger.info(f"正在从 '{model_path}' 加载YOLO模型...")
print(f"正在从 '{model_path}' 加载YOLO模型...")
self.model = YOLO(model_path)
logger.info("YOLO模型加载成功。")
print("YOLO模型加载成功。")
def detect(self, frame):
"""
@ -45,4 +44,4 @@ class ViolationDetector:
"""
# 使用YOLO自带的plot功能方便快捷
annotated_frame = result.plot()
return annotated_frame
return annotated_frame