Skip to content

Emotion detection python project #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions E/EmotionML/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.6
WORKDIR /app
COPY . /app
RUN pip wheel opencv-python
RUN pip install opencv-python
RUN pip install libgl1
RUN pip install -r requirements.txt
EXPOSE 8080
CMD python ./app.py
1 change: 1 addition & 0 deletions E/EmotionML/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Emotion detection app
54 changes: 54 additions & 0 deletions E/EmotionML/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from flask import Flask, render_template,Response
from camera import Video

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

def gen(camera):
while True:
frame=camera.get_frame()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame +
b'\r\n\r\n')

@app.route('/video')
def video():
return Response(gen(Video()),
mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__=="__main__":
from waitress import serve
serve(app, host="0.0.0.0", port=8080)


# import os
# os.environ["CUDA_VISIBLE_DEVICES"]= "-1"
# import cv2
# from deepface import DeepFace

# face_classifier = cv2.CascadeClassifier()
# face_classifier.load(cv2.samples.findFile("haarcascade_frontalface_default.xml"))

# cap = cv2.VideoCapture(0)

# while True:

# ret, frame = cap.read()
# frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# faces = face_classifier.detectMultiScale(frame_gray)

# response = DeepFace.analyze(frame, actions=("emotion",), enforce_detection=False)
# for face in faces:
# x,y,w,h = face

# cv2.rectangle(frame, (x+10,y+10), (x+w,y+h), color= (238,130,238), thickness=4)
# cv2.putText(frame, response["dominant_emotion"].upper(), org=(x,y), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
# fontScale=1.2, color=(255,204,153),thickness=4)
# cv2.imshow("", frame)
# if(cv2.waitKey(30)==27):
# break
# cap.release()
# cv2.destroyAllWindows()
30 changes: 30 additions & 0 deletions E/EmotionML/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
os.environ["CUDA_VISIBLE_DEVICES"]= "-1"
import cv2
from deepface import DeepFace

face_classifier = cv2.CascadeClassifier()
face_classifier.load(cv2.samples.findFile("haarcascade_frontalface_default.xml"))

class Video(object):
def __init__(self):
self.video=cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
ret,frame = self.video.read()
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(frame_gray)

response = DeepFace.analyze(frame, actions=("emotion",), enforce_detection=False)
for face in faces:
x,y,w,h = face

cv2.rectangle(frame, (x+10,y+10), (x+w,y+h), color= (238,130,238), thickness=4)
cv2.putText(frame, response["dominant_emotion"].upper(), org=(x,y), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=1.2, color=(255,204,153),thickness=4)
cv2.imshow("", frame)
if(cv2.waitKey(30)==27):
break
ret,jpg=cv2.imencode('.jpg',frame)
return jpg.tobytes()
Loading