目标跟踪 MOT数据集和可视化

目录

MOT15数据集格式简介

gt可视化

本人修改的GT可视化代码:


MOT15数据集格式简介

以下内容转自:【目标跟踪】MOT数据集GroundTruth可视化-腾讯云开发者社区-腾讯云

MOT15数据集下载:https://pan.baidu.com/s/1foGrBXvsanW8BI4eybqfWg?pwd=8888

以下为一行gt示例:

1,1,1367,393,73,225,1,-1,-1,-1

各列数据对应含义如下

复制代码
<frame>,<id>,<bb_left>,<bb_top>,<bb_width>,<bb_height>,<conf>,<x>,<y>,<z>

复制

  • frame:图片帧id
  • id:目标id
  • bb_left:bbox左上角坐标x
  • bb_top:bbox左上角坐标y
  • bb_width:bbox的宽度
  • bb_height:bbox的高度
  • conf:置信度
  • x:三维坐标系x值,对于二维任务填充为-1
  • y:三维坐标系y值,对于二维任务填充为-1
  • z:三维坐标系z值,对于二维任务填充为-1

gt可视化

由于是跟踪任务,因此在可视化检测框的同时进一步添加箭头,用来标识目标的运动轨迹。

处理思路是读取一张图片后,同时读取两张图片的gt,若两张图片同时包含同一个目标,则用箭头连接前一帧bbox的中心点和后一帧bbox的中心点。

只能跟踪一个人:

python 复制代码
import os

import cv2
def match_obj(obj_list, obj_id):
    try:
        index = obj_list.index(obj_id)
    except:
        index = -1
    return index

if __name__ == '__main__':

    dir_a=r'B:\data\track\MOT15\train\ADL-Rundle-6'

    img_dir=r'B:\data\track\MOT15\train\ADL-Rundle-6/'
    txt_paths = files = ['%s/%s' % (i[0].replace("\\", "/"), j) for i in os.walk(dir_a) for j in i[-1] if j.endswith(('gt.txt', '.xpng'))]
    img_i=1
    track_show=True

    img = cv2.imread(img_dir+"/img1/" + "0000{:0>2d}.jpg".format(img_i))
    img2 = img

    for txt_path in txt_paths:
        with open(txt_path, 'r') as f:
            lines = f.readlines()
        object_list = []
        center_list = []
        for line in lines:
            img_id = line.split(',')[0]
            if img_id == str(img_i):
                object_id = line.split(',')[1]
                object_list.append(object_id)
                x, y, w, h = int(line.split(',')[2]), int(line.split(',')[3]), int(line.split(',')[4]), int(line.split(',')[5])
                center1 = (int(int(x) + int(w) / 2), int(int(y) + int(h) / 2))
                center_list.append(center1)
            if img_id == str(int(img_i) + 1):
                img_i+=1
                img = cv2.imread(img_dir + "/img1/" + "0000{:0>2d}.jpg".format(img_i))
                object_id = line.split(',')[1]
                index = match_obj(object_list, object_id)
                x, y, w, h = int(line.split(',')[2]), int(line.split(',')[3]), int(line.split(',')[4]), int(line.split(',')[5])
                center2 = (int(int(x) + int(w) / 2), int(int(y) + int(h) / 2))
                if index != -1:
                    img2 = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255))
                    img2 = cv2.arrowedLine(img2, center_list[index], center2, (0, 255, 255), 1, 8, 0, 0.5)

            if track_show:
                cv2.imshow("sdf",img)
                cv2.waitKey(0)

本人修改的GT可视化代码:

python 复制代码
import sys
import base64
import os
from collections import OrderedDict

import cv2
import shutil
import glob
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
    sys.path.append(module_path)
import json


if __name__ == '__main__':

    dir_a=r'B:\data\track\MOT15\train'

    img_dir=r'B:\data\track\MOT15\train/'
    txt_paths = ['%s/%s' % (i[0].replace("\\", "/"), j) for i in os.walk(dir_a) for j in i[-1] if j.endswith(('gt.txt', '.xpng'))]

    version = '3.16.7'
    flags = {}
    lineColor = [0, 255, 0, 128]
    fillColor = [255, 0, 0, 128]

    track_show=True

    save_json=False

    for xmlpathName in txt_paths:
        xmlpathName=xmlpathName.replace("\\","/")
        dancetrack_name=xmlpathName.split("/")[-3]
        img_info = OrderedDict()
        with open(xmlpathName) as fs:
            lines = fs.readlines()
            # lines = sorted(lines)
            for line in lines:
                line = line.replace("\n", '')
                line_info = line.split(',')
                frame = line_info[0]
                frame_image_name = '{:0>6d}'.format(int(frame)) + ".jpg"
                box = [int(line_info[2]), int(line_info[3]), int(line_info[2]) + int(line_info[4]),
                       int(line_info[3]) + int(line_info[5]),int(line_info[1])]
                if frame_image_name in img_info:
                    img_info[frame_image_name].append(box)
                else:
                    img_info[frame_image_name] = [box]
            for image_name in img_info.keys():
                print(image_name)
                dic = {}
                dic['version'] = version
                dic['flags'] = flags
                dic['shapes'] = []
                img_path = dancetrack_name+"/img1/" + image_name
                img_new_name = dancetrack_name + "_" + image_name
                img_new_path = img_dir + img_path

                img = cv2.imread(img_new_path)
                imageHeight, imageWidth, _ = img.shape
                for box in img_info[image_name]:
                    shape = {}
                    shape['label'] = 'person'
                    shape['line_color'] = None
                    shape['fill_color'] = None
                    x1 = int(box[0])
                    y1 = int(box[1])
                    x2 = int(box[2])
                    y2 = int(box[3])

                    if track_show:
                        cv2.rectangle(img, (x1, y1), (x2, y2), (0,0,255), 1)
                        cv2.putText(img, "t:" + str(box[4]), (x1,y1+20), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0,0,255), 2)

                    shape['points'] = [[x1, y1], [x2, y2]]
                    shape['shape_type'] = 'rectangle'
                    shape['flags'] = {}
                    dic['shapes'].append(shape)

                if track_show:
                    cv2.putText(img, image_name, (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 1)
                    cv2.imshow("sdf",img)
                    cv2.waitKey(0)

                if save_json:
                    dic['lineColor'] = lineColor
                    dic['fillColor'] = fillColor
                    dic['imagePath'] = img_new_name
                    dic['imageData'] = base64.b64encode(open('{}'.format(img_new_path), "rb").read()).decode('utf-8')
                    dic['imageHeight'] = imageHeight
                    dic['imageWidth'] = imageWidth
                    fw = open('{}json'.format(img_new_path.replace(img_new_path.split('.')[-1], "")), 'w')
                    json.dump(dic, fw)
                    fw.close()

可视化效果如图所示:

在这里插入图片描述

相关推荐
字节跳动视频云技术团队39 分钟前
接大模型别再自己配 Key、搭代理了,火山引擎 IGA Pages 一步搞定
人工智能
阿里云大数据AI技术1 小时前
EMR Serverless StarRocks 产品介绍:从统一 OLAP 走向多模态分析与检索
人工智能
Forget the Dream2 小时前
Spring AI 2.0 系列(二):第一个 ChatClient——从注入到一次完整调用
java·人工智能·spring boot·ai·springai
郝学胜-神的一滴2 小时前
Effective Python 条款35:用类封装替代生成器异常注入
开发语言·人工智能·python·金融·pandas·scikit-learn·matplotlib
火山引擎开发者社区3 小时前
豆包工作,3 个月,800 万,20 亿
人工智能
Chuck.li3 小时前
AI 长篇创作工具选型:工作流对照与自测清单
人工智能·大模型·ai写作·网文作者·ai网文·豆包写作
aleimu3 小时前
Windows 11 右键打开 Cmder 2.0:从找不到菜单到默认使用 Cmder
前端·人工智能·后端
SwanArc技术笔记3 小时前
读技术文档,先用哪个 AI?模型指南筛选与 GPT-6.2 Astra 实操
人工智能
深海鱼在掘金3 小时前
深入浅出RAG——第21章:回顾与展望
人工智能
羲云网络3 小时前
GPT Image 2.6 GIF 交付排障:上线后为什么只剩第一帧?
图像处理·人工智能·前端开发·gif