ffmpeg -i "D:\BaiduNetdiskDownload\Anti_UAV_test_dev\02_6319_0000-1499\IR.mp4" -vf fps=fps=5 -s 256x256 %3d.bmp
修改
import os import re import csv ############################################### # 一个标签 def Annotations1_write(xmax, xmin, ymax, ymin): # print (rename)#打印文件名 index_ = str(index+897) with open(os.path.join(foldername, index_ + '.xml'), 'w') as f: f.write(f"""<annotation> <folder>{foldername}</folder> <filename>{index_}.png</filename> <source> <database>Unknown</database> </source> <size> <width>{256}</width> <height>{256}</height> <depth>{3}</depth> </size> <segmented>0</segmented>\n""") f.write(f""" <object> <name>Target</name> <pose>Unspecified</pose> <truncated>0</truncated> <difficult>0</difficult> <bndbox> <xmin>{int(xmin)}</xmin> <ymin>{int(ymin)}</ymin> <xmax>{int(xmax)}</xmax> <ymax>{int(ymax)}</ymax> </bndbox> </object>\n""") f.write("</annotation>") def class1(index): with open(os.path.join(root, foldername, 'IR_label.json'), 'r') as f: reader = csv.reader(f) result = list(reader) # print(result[5*i-1]) #取出想要的行,第5*i+4行 result = str(result[5 * index - 1]) # print(result) # 取出x,y的值 number = re.findall("\d+", result) # 正则化去掉多余字符(输出结果为列表) # print(number) number = str(number) # 转化为字符串 # print(number) xmax_ = (number.split(',')[0]) # 以,为分隔符取出各个元素 # print(xmax_) xmax = "".join(list(filter(str.isdigit, xmax_))) # 取出数字,最后是字符串 # print(xmax) # 同理 xmin_ = (number.split(',')[1]) xmin = "".join(list(filter(str.isdigit, xmin_))) # 取出数字,最后是字符串 ymax_ = (number.split(',')[2]) ymax = "".join(list(filter(str.isdigit, ymax_))) # 取出数字,最后是字符串 ymin_ = (number.split(',')[3]) ymin = "".join(list(filter(str.isdigit, ymin_))) # 取出数字,最后是字符串 return (xmax, xmin, ymax, ymin) def class2(index): with open(os.path.join(root, foldername, 'IR_label.json'), 'r') as f: reader = csv.reader(f) result = list(reader) # print(result[4*i]) #取出想要的行,第4*i行 result = str(result[4 * index]) # print(result) # 取出x,y的值 number = re.findall("\d+", result) # 正则化去掉多余字符(输出结果为列表) # print(number) number = str(number) # 转化为字符串 xmax_ = (number.split(',')[0]) # 以,为分隔符取出各个元素 # print(xmax_) xmax = "".join(list(filter(str.isdigit, xmax_))) # 取出数字,最后是字符串 # print(xmax) # 同理 xmin_ = (number.split(',')[1]) xmin = "".join(list(filter(str.isdigit, xmin_))) # 取出数字,最后是字符串 ymax_ = (number.split(',')[2]) ymax = "".join(list(filter(str.isdigit, ymax_))) # 取出数字,最后是字符串 ymin_ = (number.split(',')[3]) ymin = "".join(list(filter(str.isdigit, ymin_))) # 取出数字,最后是字符串 return (xmax, xmin, ymax, ymin) root = r'D:\BaiduNetdiskDownload\Anti_UAV_test_dev\02_6319_0000-1499' # 标签文件路径 foldername = 'images' ####换文件夹改这里 if not os.path.exists(foldername): os.mkdir(foldername) # 打开标签文件 with open(os.path.join(root, foldername, 'IR_label.json')) as label_json: # 分成两类,判断属于哪一类 lines = [] for i in label_json.readlines()[1004:1005:]: if len(i) == 19: num = 300 index = 1 while index != num: (xmax, xmin, ymax, ymin) = class1(index) Annotations1_write(xmax, xmin, ymax, ymin) index = int(index) index += 1 elif len(i) == 18: num = 300 index = 1 while index != num: (xmax, xmin, ymax, ymin) = class1(index) Annotations1_write(xmax, xmin, ymax, ymin) index = int(index) index += 1 elif len(i) == 2: num = 250 index = 1 while index != num: (xmax, xmin, ymax, ymin) = class2(index) Annotations1_write(xmax, xmin, ymax, ymin) index = int(index) index += 1 else: print('出错了')