[dd62f3]: / users / utility / GetImageStressDetection.py

Download this file

33 lines (31 with data), 1.1 kB

 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
from django.conf import settings
from PyEmotion import *
import cv2 as cv
class ImageExpressionDetect:
def getExpression(self,imagepath):
filepath = settings.MEDIA_ROOT + "\\" + imagepath
PyEmotion()
er = DetectFace(device='cpu', gpu_id=0)
# Open you default camera
# img = cv.imread('test.jpg')
# cap = cv.VideoCapture(0)
# ret, frame = cap.read()
frame, emotion = er.predict_emotion(cv.imread(filepath))
cv.imshow('Alex Corporation', frame)
cv.waitKey(0)
print("Hola Hi",filepath,"Emotion is ",emotion)
return emotion
def getLiveDetect(self):
print("Streaming Started")
PyEmotion()
er = DetectFace(device='cpu', gpu_id=0)
# Open you default camera
cap = cv.VideoCapture(0)
while (True):
ret, frame = cap.read()
frame, emotion = er.predict_emotion(frame)
cv.imshow('Press Q to Exit', frame)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()