Skip to content

Instantly share code, notes, and snippets.

@Afsalms
Created June 21, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Afsalms/d6eaab1537a77e773ba8978fa565556c to your computer and use it in GitHub Desktop.
Save Afsalms/d6eaab1537a77e773ba8978fa565556c to your computer and use it in GitHub Desktop.
import glob as gb
import uuid
from shutil import copyfile
emotions_list = ["neutral", "anger", "contempt", "disgust", "fear", "happy", "sadness", "surprise"]
emotions_folders = sorted(gb.glob("emotions/*")) #Returns a list of all folders with participant numbers
print len(emotions_folders)
def imageWithEmotionEtraction():
for x in emotions_folders:
participant = "%s" %x[-4:] #store current participant number
for sessions in sorted(gb.glob("%s/*" %x)):
for files in sorted(gb.glob("%s/*" %sessions)):
print files
current_session = files[14:-30]
print current_session
file = open(files, 'r')
emotion = int(float(file.readline()))
sourcefile_emotion = sorted(gb.glob("images/%s/%s/*" %(participant, current_session)))[-1]
# #do same for neutral image
sourcefile_neutral = sorted(gb.glob("images/%s/%s/*" %(participant, current_session)))[0]
print sourcefile_neutral
# #Generate path to put neutral image
dest_neut = "selected_set/neutral/%s" %uuid.uuid4()
# #Do same for emotion containing image
dest_emot = "selected_set/%s/%s" %(emotions_list[emotion], uuid.uuid4())
copyfile(sourcefile_neutral, dest_neut) #Copy file
copyfile(sourcefile_emotion, dest_emot) #Copy file
if __name__ == '__main__':
imageWithEmotionEtraction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment