Commit 63320e11 authored by Wandana RAK - IT18227550's avatar Wandana RAK - IT18227550

Merge branch 'feat/it18227550' into 'develop'

Change the code for Emotion detection video

See merge request !55
parents 89892984 cdc8ecba
...@@ -5,7 +5,7 @@ import sys ...@@ -5,7 +5,7 @@ import sys
import pandas as pd import pandas as pd
import numpy as np import numpy as np
location_videofile = "F:\\CDAP-PRESENTLY\\21_22-j-02\\Presently\\presently\\media\\video\\22\\publicspeech.mp4" location_videofile = "F:\\CDAP-PRESENTLY\\21_22-j-02\\Presently\\presently\\media\\video\\22\\testvideo.mp4"
cascPath = "F:\\CDAP-PRESENTLY\\21_22-j-02\\Presently\\presently\\users\\models\\abc.xml" cascPath = "F:\\CDAP-PRESENTLY\\21_22-j-02\\Presently\\presently\\users\\models\\abc.xml"
def _get_labels(): def _get_labels():
...@@ -68,9 +68,11 @@ from collections import OrderedDict ...@@ -68,9 +68,11 @@ from collections import OrderedDict
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
import cv2 import cv2
from tensorflow.keras.models import load_model from tensorflow.keras.models import load_model
def detect_emotions(location_videofile, NumberofFrames): def detect_emotions(location_videofile, NumberofFrames):
PADDING = 40 PADDING = 40
NumberofFrames = 50
emotion_labels = _get_labels() emotion_labels = _get_labels()
arry = {} arry = {}
...@@ -126,7 +128,7 @@ def detect_emotions(location_videofile, NumberofFrames): ...@@ -126,7 +128,7 @@ def detect_emotions(location_videofile, NumberofFrames):
except Exception as e: except Exception as e:
continue continue
gray_face = __preprocess_input(gray_face, True) #gray_face = __preprocess_input(gray_face, True)
gray_face = np.expand_dims(np.expand_dims(gray_face, 0), -1) gray_face = np.expand_dims(np.expand_dims(gray_face, 0), -1)
emotion_prediction = model.predict(gray_face)[0] emotion_prediction = model.predict(gray_face)[0]
...@@ -150,8 +152,8 @@ def detect_emotions(location_videofile, NumberofFrames): ...@@ -150,8 +152,8 @@ def detect_emotions(location_videofile, NumberofFrames):
vidcap.release() vidcap.release()
break break
if len(arry) == 0: if len(arry) == 0:
return "Cannot detect emotion", arry return "Neutral"
else: else:
return max(arry, key=arry.get), arry return max(arry, key=arry.get)
emo, arr1 = detect_emotions(location_videofile, 300) emo, arr1 = detect_emotions(location_videofile, 300)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment