supervision CV视觉可视化辅助工具

2024-03-28 18:20

本文主要是介绍supervision CV视觉可视化辅助工具,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

参考:
https://supervision.roboflow.com/latest/
https://github.com/roboflow/supervision/tree/develop/examples

版本:

pip install -U supervision

ultralytics-8.1.35 (大于8.1才行,不然可能会有错误AttributeError: ‘Results’ object has no attribute ‘obb’ )
supervision 0.16.0

简单案例:

import cv2
import supervision as sv
from ultralytics import YOLOimage = cv2.imread(...)
model = YOLO('yolov8s.pt')
result = model(image)[0]
detections = sv.Detections.from_ultralytics(result)len(detections)

跟踪案例

https://github.com/roboflow/supervision/tree/develop/examples/heatmap_and_track

运行结果:
在这里插入图片描述

python D:\opencv2\supervision_cv\test.py --source_weights_path "C:\Users\loong\Downloads\yolov8m (1).pt" --source_video_path  "C:\Users\loong\Downloads\istockphoto-1047817112-640_adpp_is.mp4"  --confidence_threshold 0.3 --iou_threshold 0.5 --target_video_path  output_video.mp4

具体代码:

import argparseimport cv2
from ultralytics import YOLOimport supervision as sv
from supervision.assets import VideoAssets, download_assetsdef download_video() -> str:download_assets(VideoAssets.PEOPLE_WALKING)return VideoAssets.PEOPLE_WALKING.valuedef heatmap_and_track(source_weights_path: str,source_video_path: str,target_video_path: str,confidence_threshold: float = 0.35,iou_threshold: float = 0.5,heatmap_alpha: float = 0.5,radius: int = 25,track_threshold: float = 0.35,track_seconds: int = 5,match_threshold: float = 0.99,
) -> None:### instantiate modelmodel = YOLO(source_weights_path)### heatmap configheat_map_annotator = sv.HeatMapAnnotator(position=sv.Position.BOTTOM_CENTER,opacity=heatmap_alpha,radius=radius,kernel_size=25,top_hue=0,low_hue=125,)### annotation configlabel_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)### get the video fpscap = cv2.VideoCapture(source_video_path)fps = int(cap.get(cv2.CAP_PROP_FPS))cap.release()### tracker configbyte_tracker = sv.ByteTrack(track_thresh=track_threshold,track_buffer=track_seconds * fps,match_thresh=match_threshold,frame_rate=fps,)### video configvideo_info = sv.VideoInfo.from_video_path(video_path=source_video_path)frames_generator = sv.get_video_frames_generator(source_path=source_video_path, stride=1)### Detect, track, annotate, savewith sv.VideoSink(target_path=target_video_path, video_info=video_info) as sink:for frame in frames_generator:result = model(source=frame,classes=[0],  # only person classconf=confidence_threshold,iou=iou_threshold,# show_conf = True,# save_txt = True,# save_conf = True,# save = True,device=None,  # use None = CPU, 0 = single GPU, or [0,1] = dual GPU# agnostic_nms=True)[0]detections = sv.Detections.from_ultralytics(result)  # get detectionsdetections = byte_tracker.update_with_detections(detections)  # update tracker### draw heatmapannotated_frame = heat_map_annotator.annotate(scene=frame.copy(), detections=detections)### draw other attributes from `detections` objectlabels = [f"#{tracker_id}"for class_id, tracker_id in zip(detections.class_id, detections.tracker_id)]label_annotator.annotate(scene=annotated_frame, detections=detections, labels=labels)sink.write_frame(frame=annotated_frame)if __name__ == "__main__":parser = argparse.ArgumentParser(description="Heatmap and Tracking with Supervision")parser.add_argument("--source_weights_path",required=True,help="Path to the source weights file",type=str,)parser.add_argument("--source_video_path",default=download_video(),help="Path to the source video file",type=str,)parser.add_argument("--target_video_path",default="output.mp4",help="Path to the target video file (output)",type=str,)parser.add_argument("--confidence_threshold",default=0.35,help="Confidence threshold for the model",type=float,)parser.add_argument("--iou_threshold",default=0.5,help="IOU threshold for the model",type=float,)parser.add_argument("--heatmap_alpha",default=0.5,help="Opacity of the overlay mask, between 0 and 1",type=float,)parser.add_argument("--radius",default=25,help="Radius of the heat circle",type=float,)parser.add_argument("--track_threshold",default=0.35,help="Detection confidence threshold for track activation",type=float,)parser.add_argument("--track_seconds",default=5,help="Number of seconds to buffer when a track is lost",type=int,)parser.add_argument("--match_threshold",default=0.99,help="Threshold for matching tracks with detections",type=float,)args = parser.parse_args()heatmap_and_track(source_weights_path=args.source_weights_path,source_video_path=args.source_video_path,target_video_path=args.target_video_path,confidence_threshold=args.confidence_threshold,iou_threshold=args.iou_threshold,heatmap_alpha=args.heatmap_alpha,radius=args.radius,track_threshold=args.track_threshold,track_seconds=args.track_seconds,match_threshold=args.match_threshold,)

这篇关于supervision CV视觉可视化辅助工具的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/856360

相关文章

可视化实训复习篇章

前言: 今天,我们来学习seaborn库可视化,当然,这个建立在Matplotlib的基础上,话不多说,进入今天的正题吧!当然,这个是《python数据分析与应用》书中,大家有需求的可以参考这本书。 知识点: Matplotlib中有两套接口分别是pyplot和pyylab,即绘图时候主要导入的是Matplotlib库下的两个子模块(两个py文件)matplotlib.pyplot和matp

Windows/macOS/Linux 安装 Redis 和 Redis Desktop Manager 可视化工具

本文所有安装都在macOS High Sierra 10.13.4进行,Windows安装相对容易些,Linux安装与macOS类似,文中会做区分讲解 1. Redis安装 1.下载Redis https://redis.io/download 把下载的源码更名为redis-4.0.9-source,我喜欢跟maven、Tomcat放在一起,就放到/Users/zhan/Documents

【第十三课】区域经济可视化表达——符号表达与标注

一、前言 地图最直接的表达就是使用符号表达。使用符号可以把简单的点线面要 素渲染成最直观的地理符号,提高地图的可读性。只要掌握了 ArcGIS 符号制 作的技巧,分析符号并总结出规则,就可以制作符合要求的地图+符号。 (一)符号的选择与修改 符号的选择在制图中至关重要,使用符号选择器对话框可从多个可用样式 中选择符号,并且每个符号都有一个标签用来描述其图形特征,如颜色或类型, 利用这些标签可

【python】python葡萄酒国家分布情况数据分析pyecharts可视化(源码+数据集+论文)【独一无二】

👉博__主👈:米码收割机 👉技__能👈:C++/Python语言 👉公众号👈:测试开发自动化【获取源码+商业合作】 👉荣__誉👈:阿里云博客专家博主、51CTO技术博主 👉专__注👈:专注主流机器人、人工智能等相关领域的开发、测试技术。 python葡萄酒国家分布情况数据分析pyecharts可视化(源码+数据集+论文)【独一无二】 目录 python葡

【python】python基于akshare企业财务数据对比分析可视化(源码+数据集+论文)【独一无二】

👉博__主👈:米码收割机 👉技__能👈:C++/Python语言 👉公众号👈:测试开发自动化【获取源码+商业合作】 👉荣__誉👈:阿里云博客专家博主、51CTO技术博主 👉专__注👈:专注主流机器人、人工智能等相关领域的开发、测试技术。 系列文章目录 目录 系列文章目录一、设计要求二、设计思路三、可视化分析 一、设计要求 选取中铁和贵州茅

【python】python股票量化交易策略分析可视化(源码+数据集+论文)【独一无二】

👉博__主👈:米码收割机 👉技__能👈:C++/Python语言 👉公众号👈:测试开发自动化【获取源码+商业合作】 👉荣__誉👈:阿里云博客专家博主、51CTO技术博主 👉专__注👈:专注主流机器人、人工智能等相关领域的开发、测试技术。 【python】python股票量化交易策略分析可视化(源码+数据集+论文)【独一无二】 目录 【python】pyt

【科学计算与可视化】2. pandas 基础

1. 安装 Pandas 首先,确保你已经安装了 Pandas。你可以使用以下命令安装:pip install pandas 2. 导入 Pandas 在开始使用 Pandas 之前,你需要先导入它:import pandas as pd 3. 创建数据结构 Pandas 主要有两种数据结构:Series 和 DataFrame。 3.1 Series Series 是一个一维的标签

基于感知哈希算法的视觉目标跟踪

偶然看到这三篇博文[1][2][3],提到图片检索网站TinEye和谷歌的相似图片搜索引擎的技术原理。以图搜图搜索引擎的使命是:你上传一张图片,然后他们尽全力帮你把互联网上所有与它相似的图片搜索出来。当然了,这只是他们认为的相似,所以有时候搜索结果也不一定对。事实上,以图搜图三大搜索引擎除了上面的老牌的TinEye和Google外,还有百度上线不算很久的新生儿:百度识图。之前听余凯老师的一个D

Seaborn:数据可视化的强大工具

文章目录 引言Seaborn的原理1. 底层结构2. 数据集成3. 图形类型 Seaborn的使用1. 安装与导入2. 数据加载与探索3. 绘制图形分布图关系图分类图 4. 图形定制5. 导出图形 结论 引言 在数据分析和科学计算领域,数据可视化是一个至关重要的步骤。它能够帮助我们更直观地理解数据中的模式、趋势和关联。在Python的数据可视化库中,Seaborn是一个基于ma

动手学深度学习(Pytorch版)代码实践 -计算机视觉-37微调

37微调 import osimport torchimport torchvisionfrom torch import nnimport liliPytorch as lpimport matplotlib.pyplot as pltfrom d2l import torch as d2l# 获取数据集d2l.DATA_HUB['hotdog'] = (d2l.DATA_U