Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

img_seq.py 2.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  1. import glob as gb
  2. from shutil import copyfile
  3. import sys
  4. def set_trace():
  5. """A Poor mans break point
  6. without this in iPython debugger can generate strange characters.
  7. """
  8. from IPython.core.debugger import Pdb
  9. Pdb().set_trace(sys._getframe().f_back)
  10. def imageWithEmotionExtraction():
  11. emotions = ["neutral",
  12. "anger",
  13. "contempt",
  14. "disgust",
  15. "fear",
  16. "happy",
  17. "sadness",
  18. "surprise"]
  19. # Returns a list of all folders with participant numbers
  20. participants = gb.glob("source_emotion\\*")
  21. for x in participants:
  22. # Get the last 4 characters which is the participant number
  23. part = "%s" % x[-4:]
  24. for sessions in gb.glob("%s\\*" % x):
  25. for files in gb.glob("%s\\*" % sessions):
  26. current_session = files[20:23]
  27. file = open(files, 'r')
  28. emotion = int(float(file.readline()))
  29. # get path for last image in sequence, which contains the emotion
  30. sourcefile_emotion = \
  31. gb.glob("source_images\\%s\\%s\\*" % (part,
  32. current_session))[-1]
  33. # Get path for first image which is the neutral image
  34. sourcefile_neutral = \
  35. gb.glob("source_images\\%s\\%s\\*" % (part,
  36. current_session))[0]
  37. # Generate path to put emotion image
  38. dest_emot = \
  39. "sorted_set\\%s\\%s" % (emotions[emotion],
  40. sourcefile_emotion[25:])
  41. # Generate path for neutral image
  42. dest_neut = "sorted_set\\neutral\\%s" % sourcefile_neutral[25:]
  43. # Copy files
  44. copyfile(sourcefile_emotion, dest_emot)
  45. copyfile(sourcefile_neutral, dest_neut)
  46. def main():
  47. imageWithEmotionExtraction()
  48. set_trace()
  49. if __name__ == '__main__':
  50. imageWithEmotionExtraction()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...