opencv-yolov8-目标检测

复制代码
import cv2
from ultralytics import YOLO

# 模型加载权重

model = YOLO('yolov8n.pt')

# 视频路径

cap = cv2.VideoCapture(0)

# 对视频中检测到目标画框标出来
while cap.isOpened():
    # Read a frame from the video
    success, frame = cap.read()

    if success:
        # 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(5) & 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()
相关推荐
思通数科人工智能大模型10 小时前
零售场景下的数智店商:解决盗损问题,化解隐性成本痛点
人工智能·目标检测·计算机视觉·数据挖掘·知识图谱·零售
GISer_Jing14 小时前
OpenCV头文件路径配置终极修复指南
javascript·opencv·webpack
yy_xzz18 小时前
【OpenCV + VS】C++实现动态下雪特效
c++·人工智能·opencv
xuehaisj18 小时前
菠萝蜜果实目标检测_yolo11-C3k2-ConvFormer改进
人工智能·目标检测·目标跟踪
MediaTea20 小时前
Python 第三方库:cv2(OpenCV 图像处理与计算机视觉库)
开发语言·图像处理·python·opencv·计算机视觉
化作星辰1 天前
解决 OpenCV imread 在 Windows 中读取包含中文路径图片失败的问题
人工智能·opencv·计算机视觉
zl_vslam1 天前
SLAM中的非线性优-3D图优化之李群李代数在Opencv-PNP中的应用(四)
人工智能·opencv·算法·计算机视觉
点PY1 天前
TR3D: Towards Real-Time Indoor 3D Object Detection论文精读
人工智能·目标检测·3d
菜鸟学322 天前
opencv代码分析
人工智能·opencv·计算机视觉
却道天凉_好个秋2 天前
OpenCV(二十九):高通滤波-索贝尔算子
人工智能·opencv·计算机视觉