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()
opencv-yolov8-目标检测
W_en丶2023-08-19 10:51
相关推荐
jndingxin2 小时前
OpenCV视频I/O(14)创建和写入视频文件的类:VideoWriter介绍FL16238631295 小时前
[C++]使用纯opencv部署yolov11旋转框目标检测方世恩8 小时前
【进阶OpenCV】 (5)--指纹验证FL16238631298 小时前
[C++]使用纯opencv部署yolov11-pose姿态估计onnx模型A_lvvx8 小时前
OpenCV透视变换鲸~屿9 小时前
计算机视觉 第十章OpenCVEric.Lee202110 小时前
数据集-目标检测系列- 螃蟹 检测数据集 crab >> DataBall菜就多练_082813 小时前
《深度学习》OpenCV 摄像头OCR 过程及案例解析给算法爸爸上香13 小时前
YOLOv11尝鲜测试五分钟极简配置xuehaishijue14 小时前
红外画面空中目标检测系统源码分享