当前位置:   article > 正文

opencv-yolov8-目标检测_yolov8视频流目标检测

yolov8视频流目标检测
  1. import cv2
  2. from ultralytics import YOLO
  3. # 模型加载权重
  4. model = YOLO('yolov8n.pt')
  5. # 视频路径
  6. cap = cv2.VideoCapture(0)
  7. # 对视频中检测到目标画框标出来
  8. while cap.isOpened():
  9. # Read a frame from the video
  10. success, frame = cap.read()
  11. if success:
  12. # Run YOLOv8 inference on the frame
  13. results = model(frame)
  14. # Visualize the results on the frame
  15. annotated_frame = results[0].plot()
  16. # Display the annotated frame
  17. cv2.imshow("YOLOv8 Inference", annotated_frame)
  18. # Break the loop if 'q' is pressed
  19. if cv2.waitKey(5) & 0xFF == ord("q"):
  20. break
  21. else:
  22. # Break the loop if the end of the video is reached
  23. break
  24. # Release the video capture object and close the display window
  25. cap.release()
  26. cv2.destroyAllWindows()

 

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

闽ICP备14008679号