当前位置:   article > 正文

yolov8-oprncv可视化结果,并将其显示在窗口中_yolov8 result可视化

yolov8 result可视化

流式传输源循环for

下面是一个使用 OpenCV () 和 YOLOv8 对视频帧运行推理的 Python 脚本。此脚本假定您已经安装了必要的软件包( 和 )。cv2opencv-pythonultralytics

  1. import cv2
  2. from ultralytics import YOLO
  3. # Load the YOLOv8 model
  4. model = YOLO('yolov8n.pt')
  5. # Open the video file
  6. video_path = "path/to/your/video/file.mp4"
  7. cap = cv2.VideoCapture(video_path)
  8. # Loop through the video frames
  9. while cap.isOpened():
  10. # Read a frame from the video
  11. success, frame = cap.read()
  12. if success:
  13. # Run YOLOv8 inference on the frame
  14. results = model(frame)
  15. # Visualize the results on the frame
  16. annotated_frame = results[0].plot()
  17. # Display the annotated frame
  18. cv2.imshow("YOLOv8 Inference", annotated_frame)
  19. # Break the loop if 'q' is pressed
  20. if cv2.waitKey(1) & 0xFF == ord("q"):
  21. break
  22. else:
  23. # Break the loop if the end of the video is reached
  24. break
  25. # Release the video capture object and close the display window
  26. cap.release()
  27. cv2.destroyAllWindows()

脚本将对视频的每一帧运行预测,可视化结果,并将其显示在窗口中。可以通过按“q”退出循环。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/98519
推荐阅读
相关标签
  

闽ICP备14008679号