def genConfig(seq_path, set_type):
path, seqname = os.path.split(seq_path)
if set_type == 'OTB':
############################################ have to refine #############################################
img_list = sorted([seq_path + '/img/' + p for p in os.listdir(seq_path + '/img') if os.path.splitext(p)[1] == '.jpg'])
if (seqname == 'Jogging_1') or (seqname == 'Skating2_1'):
gt = np.loadtxt(seq_path + '/groundtruth_rect.1.txt')
elif (seqname == 'Jogging_2') or (seqname == 'Skating2_2'):
gt = np.loadtxt(seq_path + '/groundtruth_rect.2.txt')
elif seqname =='Human4':
gt = np.loadtxt(seq_path + '/groundtruth_rect.2.txt', delimiter=',')
elif (seqname == 'BlurBody') or (seqname == 'BlurCar1') or (seqname == 'BlurCar2') or (seqname == 'BlurCar3') \
or (seqname == 'BlurCar4') or (seqname == 'BlurFace') or (seqname == 'BlurOwl') or (seqname == 'Board') \
or (seqname == 'Box') or (seqname == 'Car4') or (seqname == 'CarScale') or (seqname == 'ClifBar') \
or (seqname == 'Couple') or (seqname == 'Crossing') or (seqname == 'Dog') or (seqname == 'FaceOcc1') \
or (seqname == 'Girl') or (seqname == 'Rubik') or (seqname == 'Singer1') or (seqname == 'Subway') \
or (seqname == 'Surfer') or (seqname == 'Sylvester') or (seqname == 'Toy') or (seqname == 'Twinnings') \
or (seqname == 'Vase') or (seqname == 'Walking') or (seqname == 'Walking2') or (seqname == 'Woman') :
gt = np.loadtxt(seq_path + '/groundtruth_rect.txt')
else:
gt = np.loadtxt(seq_path + '/groundtruth_rect.txt', delimiter=',')
if seqname == 'David':
img_list = img_list[299:]
if seqname == 'Football1':
img_list = img_list[0:74]
if seqname == 'Freeman3':
img_list = img_list[0:460]
if seqname == 'Freeman4':
img_list = img_list[0:283]
if seqname == 'Diving':
img_list = img_list[0:215]
if seqname == 'Tiger1':
img_list = img_list[5:]
#polygon to rect
if gt.shape[1] == 8:
x_min = np.min(gt[:, [0, 2, 4, 6]], axis=1)[:, None]
y_min = np.min(gt[:, [1, 3, 5, 7]], axis=1)[:, None]
x_max = np.max(gt[:, [0, 2, 4, 6]], axis=1)[:, None]
y_max = np.max(gt[:, [1, 3, 5, 7]], axis=1)[:, None]
gt = np.concatenate((x_min, y_min, x_max - x_min, y_max - y_min), axis=1)
return img_list, gt
path, seqname = os.path.split(seq_path)#os.path.split() 返回文件的路径和文件名
img_list = sorted([seq_path + '/img/' + p for p in os.listdir(seq_path + '/img') if os.path.splitext(p)[1] == '.jpg'])
1.用库函数sorted()对字符串排序
2.os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表
3.os.path.splitext() 将文件名和扩展名分开
python split(),os.path.split()和os.path.splitext()函数用法
https://www.cnblogs.com/fengff/p/9294397.html
if gt.shape[1] == 8:
gt.shape[1] == 8#建立一个4*2的矩阵,利用shape可输出矩阵的维度,即行数和列数。shape[0]和shape[1]分别代表行和列的长度>>目标跟踪中groundtruth:(x,y,w,h),左上角+宽高,所以此处:列数==8
return img_list, gt #返回img_list和gt