import cv2 from ultralytics import YOLO # 加载 YOLOv8 模型 model = YOLO('./best.pt') video_path = "./4.mp4" cap = cv2.VideoCapture(video_path) while cap.isOpened(): status, frame = cap.read() if not status: break results = model.predict(source=frame) result = results[0] anno_frame = result.plot() cv2.imshow("V8", anno_frame) # 设置延迟以减慢视频播放速度 if cv2.waitKey(30) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()