VOT数据集下载和查看

 首先在https://github.com/votchallenge/vot-toolkit/tree/master/stacks下载对应数据集的Json文件,然后运行以下代码下载

import json
import os
import wget, tarfile, zipfile
import ssl
ssl._create_default_https_context = ssl._create_unverified_context


vot_2019_path = '/home/桌面/VOT2019/data/'  # object file
json_path = '/home/桌面/VOT2019/description.json'  # vot 2019 json file
anno_vot = 'vot2019'  # vot2019 or vot2018 or vot2017

with open(json_path, 'r') as fd:
    vot_2019 = json.load(fd)
home_page = vot_2019['homepage']

for i, sequence in enumerate(vot_2019['sequences']):
    print('download the {} sequences'.format(i + 1))
    #
    annotations = sequence['annotations']['url']
    data_url = sequence['channels']['color']['url'].split('../../')[-1]

    name = annotations.split('.')[0]
    file_name = annotations.split('.')[0] + '.zip'

    down_annotations = os.path.join(home_page, anno_vot, 'longterm', annotations)  #main longterm
                                                                      #http://data.votchallenge.net/vot2019/longterm/ballet.zip
    down_data_url = os.path.join(home_page, data_url)

    image_output_name = os.path.join(vot_2019_path, name, 'color', file_name) #http://data.votchallenge.net/sequences/578a919e272d9993be8a27b0df4b0a12845f8e99e0fd04582d97f61a939a751cf0bafd68a8f21b4a7ef4fb6aeb43732e293b598cae5a8344ead827fdef279812.zip
    anno_output_name = os.path.join(vot_2019_path, name, file_name)
    out_dir = os.path.dirname(anno_output_name)

    if os.path.exists(out_dir) == False:
        os.mkdir(out_dir)
    if os.path.exists(out_dir+'/groundtruth.txt') == True:
        pass
    else:
        # annotations download and unzip and remove it
        wget.download(down_annotations, anno_output_name)
        print('loading {} annotation'.format(name))
        # unzip
        file_zip = zipfile.ZipFile(anno_output_name, 'r')
        for file in file_zip.namelist():
            file_zip.extract(file, out_dir)
            print('extract annotation {}/{}'.format(name, file))
        file_zip.close()
        os.remove(anno_output_name)
        print('remove annotation {}.zip'.format(name))

    # image download and unzip ad remove it
    out_dir = os.path.dirname(image_output_name)
    if os.path.exists(out_dir) == False:
        os.mkdir(out_dir)
    if os.path.exists(out_dir+'/00000001.jpg') == True:
        continue
    else:
        wget.download(down_data_url, image_output_name)
        print('loading {} sequence'.format(name))

        file_zip = zipfile.ZipFile(image_output_name, 'r')
        for file in file_zip.namelist():
            file_zip.extract(file, out_dir)
            print('extract image {}'.format(file))
        file_zip.close()
        os.remove(image_output_name)
        print('remove image file {}.zip'.format(name))
        print('sequence  {} Completed!'.format(i + 1))

 

如果网络不稳定,出现异常,创建以下.sh脚本运行python代码下载

#!/bin/sh
while [ 1 ]; do
  python get_votdatasets.py
done

下载数据集,可视化查看:

import numpy as np
import cv2
import os
import tkinter
from tkinter import ttk
import tkinter.font as tkFont
from tkinter import *
video_path = '/opt/dataset/VOT2018'


def go(*args):  # 处理事件,*args表示可变参数
    print(comboxlist.get())  # 打印选中的值
    list0 = []
    target_name = comboxlist.get()
    file_paath = video_path+'/'+target_name+'/'

    for files in os.walk(file_paath):
        list0.append(files)
    img_list = []
    for ii in list0[0][2]:
        if (ii.split('.')[-1] == 'jpg'):
            img_list.append(ii)
    list_img_name = np.array(img_list)
    list_img_name.sort()

    path = file_paath + '/''groundtruth.txt'
    data = []
    for line2 in open(path):
        data.append(line2)

        # print(line2)
    data1 = []
    for i in data:
        data1.append(i[:len(i) - 1])
    data2 = []
    data3 = []
    for j in data1:
        data2.append(j.split(','))

    data4 = []
    for k in data2:
        data3 = np.array([0.0 if y == '' else float(y) for y in k])
        data4.append(data3)
    data_rect = np.array(data4)

    for num in range(0, len(list_img_name)):
        if len(data_rect[num]) > 2:
            x1 = int(data_rect[num][0])
            y1 = int(data_rect[num][1])
            x2 = int(data_rect[num][2])
            y2 = int(data_rect[num][3])
            x3 = int(data_rect[num][4])
            y3 = int(data_rect[num][5])
            x4 = int(data_rect[num][6])
            y4 = int(data_rect[num][7])

            img_file_name = file_paath + str(list_img_name[num])
            print(img_file_name)
            src = cv2.imread(img_file_name)

            cv2.line(src, (x1, y1), (x2, y2), (0, 0, 255), thickness=1)
            cv2.line(src, (x2, y2), (x3, y3), (0, 0, 255), thickness=1)
            cv2.line(src, (x3, y3), (x4, y4), (0, 0, 255), thickness=1)
            cv2.line(src, (x4, y4), (x1, y1), (0, 0, 255), thickness=1)
            cv2.putText(src, 'Press q to quit', (20, 55), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1,
                       (0,0,0), 1)
            cv2.imshow(target_name, src)
            key = cv2.waitKey(0)
            if key == ord('q'):
                cv2.destroyAllWindows()
                break
    cv2.destroyAllWindows()
    return
win = tkinter.Tk()  # 构造窗体
win.title("video list")
win.geometry('200x200+1500+300')

ft = tkFont.Font(family='Times', size=12, weight=tkFont.BOLD)
ft1 = tkFont.Font(family='Times', size=12)
ttk.Label(win, text="Chooes a video", font=ft,
          compound='center').pack()  0.grid(column=0, row=0)
com = ttk.Button(win, text='exit', command=quit)
# com.grid(column=0, row=20)

comvalue = tkinter.StringVar()  
comboxlist = ttk.Combobox(win, width=20, textvariable=comvalue, state='readonly', font=ft1) 

comboxlist["values"] = os.listdir(video_path)
# comboxlist.grid(column=0, row=1)
comboxlist.current(0)  # 选择第一个
comboxlist.bind("<>", go)  
comboxlist.pack()
com.pack(side=BOTTOM)
# print(comboxlist.get())

win.mainloop()  

 

你可能感兴趣的:(VOT数据集下载和查看)