yolo11识别视频中的物体代码如下:
#!/usr/local/python3/bin/python3
# -*- coding: utf-8 -*
from ultralytics import YOLO
import cv2
# Load the YOLOv11 model
model = YOLO('yolov11n.pt')
# Open the video file
video_name = "path_to_your_video.mp4"
cap = cv2.VideoCapture(video_name)
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()
    if success:
        # Run YOLOv11 inference on the frame
        results = model(frame)
        # Visualize the results on the frame
        annotated_frame = results[0].plot()
        # Display the annotated frame
        cv2.imshow("YOLOv8 Inference", annotated_frame)
        # Break the loop if 'q' is pressed
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    else:
        # Break the loop if the end of the video is reached
        break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()					网友回复


