yolov8预测

yoloV8 官方地址 预测 -Ultralytics YOLO 文档

1.图片预测

from ultralytics import YOLO
#### 图片预测1
###   https://www.youtube.com/watch?v=neBZ6huolkg
###   https://github.com/ultralytics/ultralytics
###   https://github.com/abdullahtarek/football_analysis


mode = YOLO("yolov8x.pt")
##将视频数据放入到模型中预测
#result = mode.predict('input_videos/08fd33_4.mp4', save=True)
results = mode.predict('input_image/111.png', save=True)

##print("================")
# for box in result[0].boxes:
#    print(box)



#https://docs.ultralytics.com/modes/predict/#key-features-of-predict-mode
for result in results:
    boxes = result.boxes  # Boxes object for bounding box outputs
    masks = result.masks  # Masks object for segmentation masks outputs
    keypoints = result.keypoints  # Keypoints object for pose outputs
    probs = result.probs  # Probs object for classification outputs
    obb = result.obb  # Oriented boxes object for OBB outputs
    result.show()  # display to screen
    result.save(filename="result.png")  # save to disk


2.视频预测

import cv2

from ultralytics import YOLO

# Load the YOLOv8 model
model = YOLO("../yolov8n.pt")

# Open the video file
video_path = "D:/workspace/ultralytics/input_videos/08fd33_4.mp4"
cap = cv2.VideoCapture(video_path)

if not cap.isOpened():
    print("打开摄视屏失败!")

# Loop through the video frames
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        print("视频读帧成功!")
        # Run YOLOv8 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:
        print("视频读帧失败!")
        # 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()

3.项目结构

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王大锤4391

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值