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
相关推荐
struggle20251 小时前
一个开源 GenBI AI 本地代理(确保本地数据安全),使数据驱动型团队能够与其数据进行互动,生成文本到 SQL、图表、电子表格、报告和 BI慕雪华年9 小时前
【Linux】opencv在arm64上提示找不到libjasper-devparadoxjun11 小时前
YOLOv8源码修改(4)- 实现YOLOv8模型剪枝(任意YOLO模型的简单剪枝)墨绿色的摆渡人12 小时前
python | OpenCV小记(一):cv2.imread(f) 读取图像操作(待更新)Quz14 小时前
OpenCV:闭运算Quz1 天前
OpenCV:开运算西猫雷婶1 天前
python学opencv|读取图像(五十二)使用cv.matchTemplate()函数实现最佳图像匹配2301_793069821 天前
OpenCV 图像旋转编程武士1 天前
OpenCV 版本不兼容导致的问题西猫雷婶1 天前
python学opencv|读取图像(五十)使用addWeighted()函数实现图像加权叠加效果