trackers目标跟踪库安装和试用

环境搭建

bash 复制代码
git clone https://github.com/roboflow/trackers.git
conda create -n trackers python=3.12.0
conda activate trackers
pip install torch==2.7.0 --index-url https://download.pytorch.org/whl/cu128               
pip install inference -i https://pypi.mirrors.ustc.edu.cn/simple/   
pip install -e . -i https://pypi.mirrors.ustc.edu.cn/simple/                   

demo测试

测试demo:

python 复制代码
import cv2
import supervision as sv
from inference import get_model
from trackers import ByteTrackTracker

model = get_model(model_id="rfdetr-medium")
tracker = ByteTrackTracker()

label_annotator = sv.LabelAnnotator()
trajectory_annotator = sv.TraceAnnotator()

cap = cv2.VideoCapture("720p60hz.mp4")

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break

    result = model.infer(frame)[0]
    detections = sv.Detections.from_inference(result)
    tracked = tracker.update(detections)

    frame = label_annotator.annotate(frame, tracked)
    frame = trajectory_annotator.annotate(frame, tracked)
    
    cv2.imshow("frame", frame)
    cv2.waitKey(1)

效果如下:

如果检测速度很慢,说明模型在cpu端运行。若需要在gpu上运行模型,需要执行:

bash 复制代码
pip uninstall onnxruntime
pip install onnxruntime-gpu -i https://pypi.mirrors.ustc.edu.cn/simple/ 
相关推荐
冬奇Lab8 小时前
Workflow 系列(04):Multi-Agent 协调——编排器边界、并发控制与上下文隔离
人工智能·工作流引擎
冬奇Lab8 小时前
每日一个开源项目(第147篇):HyperGraphRAG - 用超图表示 N 元关系,RAG 的第三代范式
人工智能·开源·graphql
甲维斯9 小时前
Github + 阿里云oss实现类似codex的自动更新!
人工智能
阿里云大数据AI技术10 小时前
光轮智能 × 阿里云:共建 Physical AI 云上数据、评测与持续学习基础设施
人工智能·机器学习
机器之心11 小时前
实锤了:Claude Code偷查用户,时区、中国AI实验室全是关键词
人工智能·openai
网易云信11 小时前
Cursor点燃个人开发者,企业级AI为何频频受挫?Agent工厂从提效工具到AI员工的跃迁
人工智能·开源
网易云信11 小时前
解锁触手可及的温暖:网易智企 x Wander Puffs AI 云游泡芙
人工智能
转转技术团队11 小时前
从 PRD 到可验证代码:AI 需求开发闭环实践
人工智能