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()
相关推荐
泛泛7辈11 小时前
通过matlab训练和验证深度学习的目标检测
深度学习·目标检测·matlab
AI棒棒牛1 天前
YOLO26损失地图绘制:只改权重和数据集路径即可生成损失地图(Loss Landscape)
人工智能·深度学习·目标检测·yolo26
sali-tec1 天前
C# 基于OpenCv的视觉工作流-章98-频域滤波
图像处理·人工智能·opencv·计算机视觉
落苜蓿蓝1 天前
多张覆盖视场的平面棋盘图片; 、对每张图片用 OpenCV 的 findChessboardCorners 检测内角点并用 corn ...
数码相机·opencv·平面
梦想三三1 天前
YOLOv5 口罩目标检测实战(一):项目整体介绍与数据准备
人工智能·yolo·目标检测
明如正午1 天前
【python】Python + OpenCV 实现视频关键帧提取与智能去重
python·opencv·音视频
azoo2 天前
SimpleBlobDetector的使用
opencv
映翰通网络2 天前
TI开发板上的边缘AI工具链:先认清OpenCV、GStreamer和TIDL
人工智能·嵌入式硬件·opencv·计算机视觉·ti
小保CPP2 天前
OpenCV C++形态学操作-腐蚀与膨胀
c++·人工智能·opencv·计算机视觉
江畔柳前堤3 天前
重新理解“方差“:从统计学到LLM的七个维度
人工智能·深度学习·神经网络·目标检测·机器学习·自然语言处理·语音识别