Skip to content
Snippets Groups Projects
Commit b943fe14 authored by Timothé Boulet's avatar Timothé Boulet :alien:
Browse files

build, add mini game

parent 1ee47b07
Branches
No related tags found
No related merge requests found
Showing
with 196 additions and 965 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
This diff is collapsed.
This diff is collapsed.
# Name of model used
modelName = 'firstModel'
modelName = 'exp903'
# Emotions provided by the dataset
emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Surprise", "Neutral"]
# Shape of input of the model
input_shape = (48, 48, 1)
......
game.py 0 → 100644
#Use your camera for processing the video. Stop by pressing Q
import cv2
import imageProcess as ip
import faceAnalysis as fa
import random
from config import emotions
cap = cv2.VideoCapture(0) #0 means we capture the first camera, your webcam probably
score = 0
t = 0
N = 15
def smileyRandom(emotionToDodge):
emotionNbr = random.randrange(0,6)
emotion = emotions[emotionNbr]
if emotion == emotionToDodge: return smileyRandom(emotion)
smileyImagePath = "data/smileys/"+emotion+".png"
smiley = cv2.imread(smileyImagePath)
return smiley, emotion
smiley, emotion = smileyRandom("")
while cap.isOpened(): #or while 1. cap.isOpened() is false if there is a problem
ret, frame = cap.read() #Read next video frame, stop if frame not well read
if not ret: break
emotionsList = ip.imageProcess(frame, returnEmotion=True)
if len(emotionsList)==1:
if emotionsList[0] == emotion: #If emotion recognized, increase score, reset smiley to mimick and write "GG!"
score += 1
cv2.putText(smiley, "Emotion reconnue !", (50,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), 2)
cv2.imshow("Smiley", smiley)
smiley, emotion = smileyRandom(emotion)
cv2.imshow("Caméra", frame) #Show you making emotional faces
cv2.putText(smiley, "Score: "+str(score), (0,0), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 2)
cv2.imshow("Smiley", smiley) #Show the smiley to mimic
if cv2.waitKey(1) & 0xFF == ord('q'): #If you press Q, stop the while and so the capture
break
if cv2.waitKey(1) & 0xFF == ord('q'): #If you press P, pass the smiley but lower your score
score -= 1
smiley, emotion = smileyRandom(emotion)
cap.release()
cv2.destroyAllWindows()
\ No newline at end of file
......@@ -4,10 +4,11 @@ import numpy as np
import faceAnalysis as fa
import timeit as ti
def imageProcess(image, writeEmotion=True, writeRectangle=True):
def imageProcess(image, writeEmotion=True, writeRectangle=True, returnEmotion=False):
#Objectives : detect faces, identify emotion associated on it, modify the image by framing faces and writing their emotions associated
facesList = []
emotionsList = []
#Import faces and eyes detectors from cv2
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+'haarcascade_frontalface_default.xml')
......@@ -34,7 +35,9 @@ def imageProcess(image, writeEmotion=True, writeRectangle=True):
if writeEmotion:
emotion = fa.detectEmotion(face_color)
cv2.putText(image, emotion, (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0), 2)
emotionsList.append(emotion)
if returnEmotion: return emotionsList
return facesList
def selectFace(image):
......
......@@ -32,7 +32,6 @@ def loadExpWData(nbrMaxImages=float('inf'), onlyDetected=False, detectedFace=Fal
break
#Add extracted data to our dataset
if len(facesDetected) == 1 or not onlyDetected: #Otherwise no face were detected or a no-face was detected as face
#Select detected face (if there is 1) or face according to the dataset
if detectedFace:
......
File moved
File moved
File moved
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment