02_process_offset.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # use the openface 2 to get the action units before this
  2. # go to- valapil@hemera4:~/Programs/OpenFace$
  3. # type- ./bin/FeatureExtraction -f "/home/valapil/Project/ForkCausal_Adithya/clipped_vid/pair_021/021S3o/021S3o.MTS_clipped.mp4"
  4. # also get the offset values
  5. import numpy as np
  6. import os
  7. AU = ["Person", "Case", "AU01", "AU02", "AU04", "AU05", "AU06", "AU07", "AU09","AU10","AU12","AU14","AU15","AU17","AU20","AU23",
  8. "AU25","AU26", "AU45"]
  9. off = ["Case", "Start", "End", "Person"]
  10. # folder where output csv files of OpenFace are stored
  11. folder = '/home/valapil/Project/ForkCausal_Adithya/csv_files'
  12. csv_files = [file for file in os.listdir(folder) if file.endswith('.csv')]
  13. def loadOffset():
  14. """
  15. get offset values for video frames
  16. :param basepath: path to where offset.csv is at
  17. :return: dictionary with {identifier: offset}('002S1g': 7}
  18. """
  19. # opening the file where offset values are present
  20. with open(os.path.join('/home/valapil/Project/ForkCausal_Adithya/offset.csv'), 'r') as f:
  21. f.readline() # read header
  22. offset = {}
  23. for row in f:
  24. id, StartEnd, second, frame = row.split(' ')[0:4]
  25. if id not in offset:
  26. offset[id] = {}
  27. offset[id][StartEnd] = int(np.ceil(float(frame)))
  28. return offset
  29. for file in csv_files:
  30. base_name, extension = os.path.splitext(file)
  31. new_name = base_name.split('.')[0]
  32. f1 = new_name[:-2]
  33. f2 = new_name[-1:]
  34. file_path = os.path.join(folder, file)
  35. offset = loadOffset()
  36. if new_name[-5] != '0':
  37. offset_file = np.hstack((new_name[:-3] + new_name[-1], offset[new_name]['start'], offset[new_name]['end'], new_name))
  38. else:
  39. offset_file = np.hstack((new_name[:-3] + new_name[-1], offset['0' + new_name]['start'], offset['0' + new_name]['end'], new_name))
  40. off = np.row_stack((off, offset_file))
  41. # file where offset values are stored as npy format
  42. np.save(f'/home/valapil/Project/ForkCausal_Adithya/offset_values.npy', off)