淘宝客网站免费建设,网页禁止访问怎么解决,环保类网站模板,wordpress直播插件这个最新的物体检测模型#xff0c;很厉害的样子#xff0c;还有物体追踪的功能。 有官方的Python代码#xff0c;直接上手试试就好#xff0c;至于理论#xff0c;有想研究在看论文了╮(╯_╰)╭ 简单介绍
YOLOv8 中可用的模型
YOLOv8 模型的每个类别中有五个模型用于检… 这个最新的物体检测模型很厉害的样子还有物体追踪的功能。 有官方的Python代码直接上手试试就好至于理论有想研究在看论文了╮(╯_╰)╭ 简单介绍
YOLOv8 中可用的模型
YOLOv8 模型的每个类别中有五个模型用于检测、分割和分类。YOLOv8 Nano 是最快和最小的而 YOLOv8 Extra Large (YOLOv8x) 是其中最准确但最慢的。用来实际使用的时候选权重模型。 | YOLOv8n | YOLOv8s | YOLOv8m | YOLOv8l | YOLOv8x | 其他介绍就不用管了上手玩一下要紧。看一下几个官方介绍图片就懂了 这里可以看到有物体检测识别检测分类轨迹姿态的功能下面就上手试试。 部署-简单使用【超简单】 前提安装好Python版本需要Python3.8 我的是 Python 3.11.3 视频图片识别 首先先下载官方的代码。官网代码 执行安装与检测【执行位置是在项目目录下】
pip install -r requirements.txt
pip install ultralytics# 执行这个会自动下载模型
# Downloading https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt to yolov8n.pt...
# source 替换成需要检测的本地图片即可
yolo predict modelyolov8n.pt sourcehttps://ultralytics.com/images/bus.jpg# 也可以如下对视频进行检测
yolo taskdetect modepredict modelyolov8n.pt sourceC:\Users\Administrator\Desktop\sssss-1.mp4 showTrue#实例分割
yolo tasksegment modepredict modelyolov8n-seg.pt sourceC:\Users\Administrator\Desktop\sssss-1.mp4 showTrue看看这个检测出来的效果 是不是灰常的简单[](▽)* 就酱紫后面在试试其他功能。 视频流摄像头识别
这个处理只需要把来源替换成0即可就像这样
yolo taskdetect modepredict modelyolov8n.pt source0 showTrue视频追踪-绘制随时间变化的轨迹【这个有意思】
可以用于视频追踪的模型是YOLOv8n, YOLOv8n-seg and YOLOv8n-pose 【以8n举例子】
yolo track modelyolov8n.pt source0 showTrue 这个追踪的效果就是在识别里面多了一个ID表示固定的物体。
以下是官方代码改了一下绘制随时间变化的轨迹
效果是这样的 这个车流比较多感觉轨迹画的不怎么好看。 哈哈这个卡车还识别错了 。。╮(╯▽╰)╭ 不过这里可以绘制轨迹就也可以统计这个ID物体在视频中存在的时间什么的。如果放在门店咖啡厅的摄像头里面就可以看到顾客的停留时间。
这个轨迹变化绘制物体追踪代码如下
# 绘制随时间变化的轨迹
from collections import defaultdictimport cv2
import numpy as npfrom ultralytics import YOLO# Load the YOLOv8 model
model YOLO(yolov8n.pt)# Open the video file
# video_path C:\\Users\\Administrator\\Desktop\\1.ts
video_path 0
cap cv2.VideoCapture(video_path)# Store the track history
track_history defaultdict(lambda: [])# 用于保存图像
# fourcc cv2.VideoWriter_fourcc(*mp4v)
# out_cat cv2.VideoWriter(C:\\Users\\Administrator\\Desktop\\save.mp4, fourcc, 24, (352, 288), True) # 保存位置/格式# Loop through the video frames
while cap.isOpened():# Read a frame from the videosuccess, frame cap.read()if success:# Run YOLOv8 tracking on the frame, persisting tracks between framesresults model.track(frame, persistTrue)# Get the boxes and track IDsboxes results[0].boxes.xywh.cpu()if results[0].boxes.id is not None:track_ids results[0].boxes.id.int().cpu().tolist()# Visualize the results on the frameannotated_frame results[0].plot()# Plot the tracksif results[0].boxes.id is not None:for box, track_id in zip(boxes, track_ids):x, y, w, h boxtrack track_history[track_id]track.append((float(x), float(y))) # x, y center pointif len(track) 30: # retain 90 tracks for 90 framestrack.pop(0)# Draw the tracking linespoints np.hstack(track).astype(np.int32).reshape((-1, 1, 2))cv2.polylines(annotated_frame, [points], isClosedFalse, color(track_id*10%255, 100, 255), thickness2)# Display the annotated framecv2.imshow(YOLOv8 Tracking, annotated_frame)# out_cat.write(annotated_frame) # 保存视频# Break the loop if q is pressedif cv2.waitKey(1) 0xFF ord(q):breakelse:# Break the loop if the end of the video is reachedbreak# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()参考资料
V8官方开源地址ultralytics https://github.com/ultralytics/ultralyticsMMYOLO 开源地址https://github.com/open-mmlab/mmyolo/tree/dev/configs/yolov8https://zhuanlan.zhihu.com/p/633779645?utm_id0https://blog.csdn.net/caobin_cumt/article/details/131009067关键的资料https://github.com/open-mmlab/mmyolo/blob/dev/configs/yolov8/README.md