csv_convert.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import argparse
  2. import csv
  3. import os
  4. from tqdm import tqdm
  5. def run(csv_path, save_folder):
  6. if not os.path.exists(csv_path):
  7. print(csv_path, 'not exist')
  8. return
  9. if not os.path.exists(save_folder):
  10. os.makedirs(save_folder)
  11. csv_file = csv.reader(open(csv_path, 'r'))
  12. cnt = 1
  13. for line in tqdm(csv_file):
  14. # 文件名
  15. name = line[0].split('/')[-1]
  16. print(name)
  17. if cnt != 1:
  18. with open(save_folder + '/' + name + '.csv', 'a', encoding='utf-8') as fp:
  19. # 打印四个点信息
  20. ll = line[7:]
  21. height = int(ll[4].split(':')[-1])
  22. width = int(ll[5][16:-1])
  23. # print(height*width)
  24. for i in range(0, 24, 6):
  25. x = float(ll[i].split(':')[-1])
  26. y = float(ll[i+1].split(':')[-1])
  27. text = str(width*x/100) + ' ' + str(height*y/100) + '\n'
  28. fp.write(text)
  29. fp.close()
  30. cnt += 1
  31. if __name__ == '__main__':
  32. parser = argparse.ArgumentParser()
  33. parser.add_argument('--csv_path', type=str, default='my_data_1.0.1.csv')
  34. parser.add_argument('--save_folder', type=str, default='./convert_result')
  35. args = parser.parse_args()
  36. run(args.csv_path, args.save_folder)