Created
June 21, 2017 10:45
-
-
Save Afsalms/d6eaab1537a77e773ba8978fa565556c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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