VOT2015以后groundtruth从4变为8的原因:
在使用vot数据集时一个令人疑惑的地方是,一般来说groundtruth由四个值(cx,cy,w,h)(矩形中心坐标加矩形长宽)或者(x,y,w,h)(左上角点坐标和长宽)四个数据进行表示即可,但是在vot数据集中每一个groundtruth确有8个数值。此时,四个角点确定的bounding box并不是与坐标轴平行的,是有一定旋转角度的矩形框。
所以如果需要使用轴对齐的bounding box(groundtruth为4个值),就需要对数据进行转化,github项目pysot(位于/pysot-master/utils/bbox.py)提供的代码如下:
def get_axis_aligned_bbox(region):
# region = np.array([region[0][0][0], region[0][0][1], region[0][1][0], region[0][1][1],
# region[0][2][0], region[0][2][1], region[0][3][0], region[0][3][1]])
cx = np.mean(region[0::2])
# print(cx)
cy = np.mean(region[1::2])
# print(cy)
x1 = min(region[0::2])
# print(x1)
x2 = max(region[0::2])
# print(x2)
y1 = min(region[1::2])
# print(y1)
y2 = max(region[1::2])
# print(y2)
A1 = np.linalg.norm(region[0:2] - region[2:4]) * np.linalg.norm(region[2:4] - region[4:6])
A2 = (x2 - x1) * (y2 - y1)
s = np.sqrt(A1 / A2)
w = s * (x2 - x1) + 1
h = s * (y2 - y1) + 1
return cx, cy, w, h
但是这种方法并不能直接用,于是我自己写了段代码,让他能被实现:
#自己的groundtruth.txt文件的路径
f = open("D:/vot2020/baby/groundtruth.txt",encoding = "utf-8")
regiont=f.read()
regiont=re.sub('[\n]',',',regiont)
b = list(regiont.split(","))
a=[]
t=0
for i in b[:-1]:
#插入数据
a.append(float(i))
t=t+1
if t==8:
region = np.array(a)
c=str(get_axis_aligned_bbox(region))[1:-1]
# 将转换的结果储存的位置
with open('D:/vot2020/baby/test_office.txt', 'a', encoding='utf-8') as file:
file.write(c+'\n')
t=0
因为这里是一个一个seq里的groundtruth.txt文件发生变化,且txt文件里面保存的数据小数点位数太多,故而我做了以下改进:
import re
import numpy as np
def get_axis_aligned_bbox(region):
# region = np.array([region[0][0][0], region[0][0][1], region[0][1][0], region[0][1][1],
# region[0][2][0], region[0][2][1], region[0][3][0], region[0][3][1]])
cx = round(np.mean(region[0::2]),1)
# print(cx)
cy = round(np.mean(region[1::2]),1)
# print(cy)
x1 = min(region[0::2])
# print(x1)
x2 = max(region[0::2])
# print(x2)
y1 = min(region[1::2])
# print(y1)
y2 = max(region[1::2])
# print(y2)
A1 = np.linalg.norm(region[0:2] - region[2:4]) * np.linalg.norm(region[2:4] - region[4:6])
A2 = (x2 - x1) * (y2 - y1)
s = np.sqrt(A1 / A2)
w = round(s * (x2 - x1) + 1,1)
h = round(s * (y2 - y1) + 1,1)
return cx, cy,w, h
# seqlist_path='data/rgbt234.txt'
# with open(seqlist_path,'r') as fp:
# seq_list = fp.read().splitlines()
# for i in seq_list:
# print(i)
# 自己的groundtruth.txt文件的路径
seqlist_path='D:/vot2020/list.txt'
with open(seqlist_path,'r') as fp:
seq_list = fp.read().splitlines()
for i in seq_list:
print(i)
f = open("D:/vot2020/"+i+"/groundtruth.txt",encoding = "utf-8")
regiont=f.read()
regiont=re.sub('[\n]',',',regiont)
b = list(regiont.split(","))
a=[]
t=0
for m in b[:-1]:
#插入数据
a.append(float(m))
t=t+1
if t==8:
region = np.array(a)
c=str(get_axis_aligned_bbox(region))[1:-1]
# 将转换的结果储存的位置
with open("D:/vot2020/"+i+"/ground_truth.txt", 'a', encoding='utf-8') as file:
file.write(c+'\n')
t=0
这样直接执行一次就可以把所有的groundtruth.txt文件全部进行处理,且数据全改为保留一位小数:
参考CSDN:
1.VOT 数据集 groundtruth 8个维度 转成 4个维度的方法
2.VOT2016数据集groundtruth每行有八个数据的原因