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

相关文章

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

Python 交互式可视化的利器Bokeh的使用

《Python交互式可视化的利器Bokeh的使用》Bokeh是一个专注于Web端交互式数据可视化的Python库,本文主要介绍了Python交互式可视化的利器Bokeh的使用,具有一定的参考价值,感... 目录1. Bokeh 简介1.1 为什么选择 Bokeh1.2 安装与环境配置2. Bokeh 基础2

基于Python打造一个可视化FTP服务器

《基于Python打造一个可视化FTP服务器》在日常办公和团队协作中,文件共享是一个不可或缺的需求,所以本文将使用Python+Tkinter+pyftpdlib开发一款可视化FTP服务器,有需要的小... 目录1. 概述2. 功能介绍3. 如何使用4. 代码解析5. 运行效果6.相关源码7. 总结与展望1

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

使用Folium在Python中进行地图可视化的操作指南

《使用Folium在Python中进行地图可视化的操作指南》在数据分析和可视化领域,地图可视化是一项非常重要的技能,它能够帮助我们更直观地理解和展示地理空间数据,Folium是一个基于Python的地... 目录引言一、Folium简介与安装1. Folium简介2. 安装Folium二、基础使用1. 创建

基于Python开发PDF转PNG的可视化工具

《基于Python开发PDF转PNG的可视化工具》在数字文档处理领域,PDF到图像格式的转换是常见需求,本文介绍如何利用Python的PyMuPDF库和Tkinter框架开发一个带图形界面的PDF转P... 目录一、引言二、功能特性三、技术架构1. 技术栈组成2. 系统架构javascript设计3.效果图

Python中的可视化设计与UI界面实现

《Python中的可视化设计与UI界面实现》本文介绍了如何使用Python创建用户界面(UI),包括使用Tkinter、PyQt、Kivy等库进行基本窗口、动态图表和动画效果的实现,通过示例代码,展示... 目录从像素到界面:python带你玩转UI设计示例:使用Tkinter创建一个简单的窗口绘图魔法:用

Python:豆瓣电影商业数据分析-爬取全数据【附带爬虫豆瓣,数据处理过程,数据分析,可视化,以及完整PPT报告】

**爬取豆瓣电影信息,分析近年电影行业的发展情况** 本文是完整的数据分析展现,代码有完整版,包含豆瓣电影爬取的具体方式【附带爬虫豆瓣,数据处理过程,数据分析,可视化,以及完整PPT报告】   最近MBA在学习《商业数据分析》,大实训作业给了数据要进行数据分析,所以先拿豆瓣电影练练手,网络上爬取豆瓣电影TOP250较多,但对于豆瓣电影全数据的爬取教程很少,所以我自己做一版。 目

计算机视觉工程师所需的基本技能

一、编程技能 熟练掌握编程语言 Python:在计算机视觉领域广泛应用,有丰富的库如 OpenCV、TensorFlow、PyTorch 等,方便进行算法实现和模型开发。 C++:运行效率高,适用于对性能要求严格的计算机视觉应用。 数据结构与算法 掌握常见的数据结构(如数组、链表、栈、队列、树、图等)和算法(如排序、搜索、动态规划等),能够优化代码性能,提高算法效率。 二、数学基础

基于SSM+Vue+MySQL的可视化高校公寓管理系统

系统展示 管理员界面 宿管界面 学生界面 系统背景   当前社会各行业领域竞争压力非常大,随着当前时代的信息化,科学化发展,让社会各行业领域都争相使用新的信息技术,对行业内的各种相关数据进行科学化,规范化管理。这样的大环境让那些止步不前,不接受信息改革带来的信息技术的企业随时面临被淘汰,被取代的风险。所以当今,各个行业领域,不管是传统的教育行业