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()
相关推荐
在世修行8 小时前
二值化技术详解
图像处理·opencv·计算机视觉·二值化
FriendshipT11 小时前
Ultralytics:解读C3k2模块
人工智能·pytorch·python·深度学习·目标检测
动物园猫12 小时前
道路车辆目标检测数据集:8类别、2,600张图像 | 目标检测
人工智能·目标检测·目标跟踪
小保CPP12 小时前
OCR C++ Tesseract从OpenCV中获取图片
c++·人工智能·opencv·ocr·模式识别·光学字符识别
OpenApi.cc13 小时前
tiktok-person-detection || tiktok-scene-detection
人工智能·深度学习·神经网络·目标检测·数据挖掘
带娃的IT创业者13 小时前
赋予AI“品味”:拒绝平庸,OpenCV如何重塑生成式内容的审美边界
人工智能·opencv·计算机视觉·生成式ai·内容过滤·ai审美
guo_xiao_xiao_1 天前
YOLOv11道路桥梁裂缝与坑洼目标检测数据集
人工智能·yolo·目标检测
CoderIsArt1 天前
切片辅助超推理(SAHI):一种用于小目标检测的通用框架
人工智能·目标检测·计算机视觉
皓悦编程记1 天前
【YOLO26系列】基于YOLO26的面部表情检测系统【python源码+Pyqt5界面/WEB+数据集+训练代码】
人工智能·yolo·目标检测·开源·yolo26
CHY_1281 天前
Arm Ethos‑U65:YOLOv8n 模型准备与 Vela 编译
arm开发·人工智能·yolo·目标检测