txt格式数据:
代码:
s1=""" """s2=""""""with open('/home/xingyuzhou/Desktop/test_GT.txt','r') as textlist: for text in textlist: text = text.strip().split() image_name = text[0] image_num = int(text[1]) ob2 = '' x1 = 'car' x3 = text[2:6] if image_num > 1: # extra annotation for i in range(2,image_num+1): y = text[4*(i-1)+2:4*i+2] ob2+='\n' + s1.format(x1,y[0],y[1],y[2],y[3]) savename = image_name.split('.')[0] + '.xml' file = open('/home/xingyuzhou/data/%s'%savename,'w') # with open('/home/bnrc/data/%s'%savename,'a') as file: ob1=s2.format(image_name, x1, x3[0],x3[1],x3[2],x3[3], ob2) file.write(ob1) file.close() VOC2007 {0}