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()
相关推荐
xiaohouzi1122332 天前
OpenCV的cv2.VideoCapture如何加GStreamer后端
人工智能·opencv·计算机视觉
荼蘼2 天前
答题卡识别改分项目
人工智能·opencv·计算机视觉
羊羊小栈2 天前
基于「YOLO目标检测 + 多模态AI分析」的遥感影像目标检测分析系统(vue+flask+数据集+模型训练)
人工智能·深度学习·yolo·目标检测·毕业设计·大作业
张子夜 iiii2 天前
4步OpenCV-----扫秒身份证号
人工智能·python·opencv·计算机视觉
潮汐退涨月冷风霜2 天前
数字图像处理(1)OpenCV C++ & Opencv Python显示图像和视频
c++·python·opencv
paid槮2 天前
机器视觉之图像处理篇
图像处理·opencv·计算机视觉
小王爱学人工智能3 天前
OpenCV一些进阶操作
人工智能·opencv·计算机视觉
猫天意3 天前
【目标检测】metrice_curve和loss_curve对比图可视化
人工智能·深度学习·目标检测·计算机视觉·cv
山烛3 天前
OpenCV:图像透视变换
人工智能·opencv·计算机视觉·图像透视变换
星期天要睡觉3 天前
计算机视觉(opencv)实战二十一——基于 SIFT 和 FLANN 的指纹图像匹配与认证
人工智能·opencv·计算机视觉