Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • automatants/facial-expression-detection
  • 2021romandfra/facial-expression-detection
2 results
Select Git revision
  • master
1 result
Show changes

Commits on Source 7

Showing with 563 additions and 437 deletions
......@@ -2,20 +2,14 @@
### Description :
Le projet a pour but de construire un programme pour détecter les visages et leurs émotions associées depuis une image ou une vidéo prise en temps réelle. Dans un second temps, il pourra être éventuellement amélioré avec la traduction des visages en avatar.
Le projet a pour but de construire un programme pour détecter les visages et leurs émotions associées depuis une image ou une vidéo prise en temps réelle. Les visages sont détectés et classifiés parmi 7 émotions : Angry, Disgust, Fear, Happy, Sad, Surprise et Neutral.
### Fonctions des différents fichiers :
### Fichiers python à lancer :
videoCapture.py : prend une vidéo en entrée, traite chaque frame avec imageProcess.py et renvoie la vidéo traitée ainsi
videoCapture.py : prend une vidéo en entrée, traite chaque frame avec imageProcess.py et renvoie la vidéo traitée ainsi. Les visages sont détectés et classifiés.
imageProcess.py : contient les fonctions pour traiter les images, qui font appel à faceAnalysis.py
faceAnalysis.py : contient les fonctions pour analyser les visages, utilise le modèle spécifié dans config.py
config.py : on y précise le modèle utilisé
utils.py : quelques fonctions utiles
data : contient les dataset, ignoré par git donc vous devez mettre les données dedans vous mêmes
models : contient les différents modèles utilisés
game.py : lance une capture de la vidéo et des smileys à imiter le plus rapidement possible.
Paramètres de game():
- playTime : durée du jeu
- dt_required : délai durant lequel l'émotion doit être reconnue en continu pour être validée
- n_photos : nombre de photos souvenirs que le modèle prendra pendant le jeu, affichées à la fin
No preview for this file type
File added
No preview for this file type
No preview for this file type
File added
This diff is collapsed.
#Objective of this file is to analyse a face
import keras
print("Chargement du modèle...")
import numpy as np
import cv2
from utils import *
from config import emotions, input_shape, modelName
......
#Use your camera for processing the video. Stop by pressing Q
from time import monotonic_ns
from numpy.core.arrayprint import _make_options_dict
def smileyRandom(emotionToDodge):
#Return a random smiley and te emotion associated
import cv2
import imageProcess as ip
import faceAnalysis as fa
import random
from time import sleep
from config import emotions
cap = cv2.VideoCapture(4) #0 means we capture the first camera, your webcam probably
score = 0
N = 15
def smileyRandom(emotionToDodge):
emotionNbr = random.randrange(0,6)
emotion = emotions[emotionNbr]
if emotion == emotionToDodge: return smileyRandom(emotion)
......@@ -18,35 +17,103 @@ def smileyRandom(emotionToDodge):
smiley = cv2.imread(smileyImagePath)
return smiley, emotion
def game(playTime = 30, invincibleFrame=0.5, dt_required=0.5, n_photos=None):
#Play a game.
# playTime : durée de jeu
# invincibleFrame : durée minimale entre deux émotions
# dt_required : durée minimal nécessaire pour valider une émotion
# n_photos : nombre de photos prises
#Use your camera for processing the video. Stop by pressing Q
import cv2
import matplotlib.pyplot as plt
import imageProcess as ip
import time
cap = cv2.VideoCapture(0) #0 means we capture the first camera, your webcam probably
score = 0
timeScoring = time.time() #last instant an emotion was found.
timeInitial = time.time()
timeSinceOtherEmotions = time.time()
timeLastPhoto = time.time()
smiley, emotion = smileyRandom("")
smileyNeutral = smiley.copy()
photos= []
while cap.isOpened(): #or while 1. cap.isOpened() is false if there is a problem
while cap.isOpened():
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 emotion in emotionsList: #If emotion recognized, increase score, reset smiley to mimick and write "GG!"
if time.time()-timeSinceOtherEmotions > dt_required: #If emotions maintained for dt seconds, score is increased and a new smiley is generated
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)
smileyNeutral = smiley.copy()
timeScoring = time.time()
timeSinceOtherEmotions = time.time()
elif emotion in emotionsList and time.time()-timeScoring>invincibleFrame: #If emotion recognized, increase score, reset smiley to mimick, start timer for impossibility of scoring (0.5s)
pass
else:
timeSinceOtherEmotions = time.time()
cv2.imshow("Camera", frame) #Show you making emotional faces
#Modify and show photos
smiley = smileyNeutral.copy()
cv2.imshow("Caméra", frame) #Show you making emotional faces
cv2.putText(smiley, "Score: "+str(score), (40,40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 2)
cv2.putText(smiley, "Timer: "+str(round(time.time()-timeInitial, 1)), (20,240), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0), 2)
cv2.imshow("Smiley", smiley) #Show the smiley to mimic
#sleep(0.5)
#Save temporarily photo:
if n_photos is not None:
if time.time()-timeLastPhoto > playTime/(n_photos+1):
timeLastPhoto = time.time()
photos.append(frame)
#Stop game if Q pressd or time exceed play time.
if cv2.waitKey(1) & 0xFF == ord('q'): #If you press Q, stop the while and so the capture
break
elif cv2.waitKey(1) & 0xFF == ord('p'): #If you press P, pass the smiley but lower your score
score -= 1
smiley, emotion = smileyRandom(emotion)
smileyNeutral = smiley.copy()
timeScoring = time.time()
timeSinceOtherEmotions = time.time()
elif time.time() - timeInitial > playTime:
break
cap.release()
cv2.destroyAllWindows()
print(f"Jeu terminé ! Vous avez imité {score} emotions en {playTime} secondes !")
if n_photos is not None:
print("Voici quelques photos prises lors de votre performance =)")
for photo in photos:
plt.imshow(photo)
plt.xticks([])
plt.yticks([])
plt.show()
if __name__ == "__main__":
game()
......@@ -57,6 +57,7 @@ def selectFace(image):
face = image[y:y+h, x:x+w]
return face
#Some tests here.
# image = cv2.imread("cagnol.jpg", 1) #Load Cagnol colored image
# imageProcess(image)
# cv2.imshow("Cagnol", image)
......
from game import *
from videoCapture import *
#game(playTime=40, invincibleFrame=1, dt_required=0.3, n_photos=5)
videoCapture()
\ No newline at end of file
This diff is collapsed.
File added
File added
File added
File moved
def videoCapture():
#Use your camera for processing the video. Stop by pressing Q
import cv2
import imageProcess as ip
......@@ -10,7 +14,7 @@ while cap.isOpened(): #or while 1. cap.isOpened() is false if there is a probl
ip.imageProcess(frame) #Process frame
cv2.imshow("Image traitée", frame) #Show processed image in a window
cv2.imshow("Image", frame) #Show processed image in a window
if cv2.waitKey(1) & 0xFF == ord('q'): #If you press Q, stop the while and so the capture
break
......