|
|
@ -26,40 +26,67 @@ def main(): |
|
|
|
video_folders = setup() |
|
|
|
for folder_info in video_folders: |
|
|
|
foldername, video_path, image_paths = folder_info |
|
|
|
print(1) |
|
|
|
run(image_paths, foldername, video_path) |
|
|
|
saveToJson() |
|
|
|
|
|
|
|
def processImage(image, idx, foldername, video_path): |
|
|
|
try: |
|
|
|
|
|
|
|
# Initialize variables to accumulate sums |
|
|
|
sums = { |
|
|
|
'angry': 0, |
|
|
|
'disgust': 0, |
|
|
|
'fear': 0, |
|
|
|
'happy': 0, |
|
|
|
'sad': 0, |
|
|
|
'surprise': 0, |
|
|
|
'neutral': 0 |
|
|
|
} |
|
|
|
|
|
|
|
anaylse_obj = DeepFace.analyze( |
|
|
|
img_path=image, |
|
|
|
actions=['emotion'], |
|
|
|
enforce_detection=True, |
|
|
|
detector_backend=backends[0] |
|
|
|
detector_backend=backends[3] |
|
|
|
) |
|
|
|
|
|
|
|
print(anaylse_obj) |
|
|
|
|
|
|
|
emotions = anaylse_obj[0]['emotion'] |
|
|
|
|
|
|
|
raw_emotions = [value for value in emotions.values()] |
|
|
|
num_of_faces = len(anaylse_obj) |
|
|
|
|
|
|
|
# Get average emotion |
|
|
|
for face in anaylse_obj: |
|
|
|
emotions = face['emotion'] |
|
|
|
for emotion in sums: |
|
|
|
sums[emotion] += emotions.get(emotion, 0) |
|
|
|
|
|
|
|
averages = {emotion: sums[emotion] / num_of_faces for emotion in sums} |
|
|
|
|
|
|
|
print(f"averages: {averages}") |
|
|
|
|
|
|
|
raw_emotions = [value for value in averages.values()] |
|
|
|
|
|
|
|
normalized_emotions = [value / 100 for value in raw_emotions] |
|
|
|
|
|
|
|
normalised_emotions = l2_normalize(np.array(raw_emotions)) |
|
|
|
#normalised_emotions = l2_normalize(np.array(raw_emotions)) |
|
|
|
|
|
|
|
normalised_emotions = normalised_emotions.tolist() |
|
|
|
# normalised_emotions = normalised_emotions.tolist() |
|
|
|
|
|
|
|
entry = { |
|
|
|
"folder": foldername, |
|
|
|
"frame": image, # Extract the filename from the path |
|
|
|
"video": video_path, |
|
|
|
"vector": normalised_emotions |
|
|
|
"faces": num_of_faces, |
|
|
|
"vector": normalized_emotions |
|
|
|
} |
|
|
|
|
|
|
|
# Add the entry to the JSON data list |
|
|
|
embeddings.append(entry) |
|
|
|
except: |
|
|
|
pass |
|
|
|
print("Could not locate face in image. Skipping.") |
|
|
|
#print("Could not locate face in image. Skipping.") |
|
|
|
|
|
|
|
|
|
|
|
def setup(): |
|
|
|