12345678910111213141516171819202122232425262728293031323334353637383940 |
- import argparse
- import csv
- import os
- from tqdm import tqdm
- def run(csv_path, save_folder):
- if not os.path.exists(csv_path):
- print(csv_path, 'not exist')
- return
- if not os.path.exists(save_folder):
- os.makedirs(save_folder)
- csv_file = csv.reader(open(csv_path, 'r'))
- cnt = 1
- for line in tqdm(csv_file):
- # 文件名
- name = line[0].split('/')[-1]
- print(name)
- if cnt != 1:
- with open(save_folder + '/' + name + '.csv', 'a', encoding='utf-8') as fp:
- # 打印四个点信息
- ll = line[7:]
- height = int(ll[4].split(':')[-1])
- width = int(ll[5][16:-1])
- # print(height*width)
- for i in range(0, 24, 6):
- x = float(ll[i].split(':')[-1])
- y = float(ll[i+1].split(':')[-1])
- text = str(width*x/100) + ' ' + str(height*y/100) + '\n'
- fp.write(text)
- fp.close()
- cnt += 1
- if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument('--csv_path', type=str, default='my_data_1.0.1.csv')
- parser.add_argument('--save_folder', type=str, default='./convert_result')
- args = parser.parse_args()
- run(args.csv_path, args.save_folder)
|