Repository for M.A.I.L system's analysis server.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

coordinate_g.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import pandas as pd
  2. import os
  3. import sys
  4. target_dir = str(sys.argv[1])
  5. full_list = os.listdir(target_dir)
  6. csv_list = [file for file in full_list if file.startswith('cam')]
  7. csv_list = sorted(csv_list)
  8. #csv_list = [cam1.csv,cam2.csv]
  9. #print(csv_list)
  10. d1 = pd.read_csv(os.path.join(target_dir,csv_list[0]))
  11. if len(csv_list) != 1 :
  12. d2 = pd.read_csv(os.path.join(target_dir,csv_list[1]))
  13. d2['x'] = 1920 - d2['x']
  14. df_conc = pd.concat([d1,d2])
  15. if len(d1) == 0 and len(d2) == 0:
  16. dummy_dic = {'x':[0,1920], 'y':[1080,0], 'z':[1.0,5.0], 'frame':[1,1900]}
  17. df_conc = pd.DataFrame(dummy_dic)
  18. df_conc.sort_values(by='frame')
  19. df_conc.drop_duplicates(['frame'])
  20. #print(df_conc)
  21. df_global = pd.DataFrame(index=range(0,int(df_conc['frame'].iloc[-1])+1), columns=['x','y','z','frame'])
  22. df_global['frame'] = list(range(1, int(df_conc['frame'].iloc[-1]+2)))
  23. df_global = df_global.astype({'frame':'int'})
  24. #print(df_global)
  25. df_global = pd.concat([df_global,df_conc])
  26. df_global=df_global.sort_values(by = ['frame'])
  27. df_global = df_global.drop_duplicates(['frame'], keep='last')
  28. df_global = df_global.reset_index(drop=True)
  29. df_global = df_global.interpolate()
  30. df_global = df_global.interpolate(method='values')
  31. #print(df_global)
  32. df_global['x'] = 10 * ((df_global['x'] - df_global['x'].min()) / (df_global['x'].max() - df_global['x'].min())) - 5
  33. df_global['y'] = 10 * ((df_global['y'] - df_global['y'].min()) / (df_global['y'].max() - df_global['y'].min())) - 5
  34. df_global['z'] = 2.7 * ((df_global['z'] - df_global['z'].min()) / (df_global['z'].max() - df_global['z'].min())) + 0.3
  35. #print(df_global)
  36. df_global = df_global.fillna(0)
  37. df_summary = df_global[df_global['frame']% 30 == 1]
  38. #print(df_summary)
  39. df_global.to_csv(os.path.join(target_dir,'coordinate.csv'))
  40. df_summary.to_csv(os.path.join(target_dir,'coordinate_summary.csv'))