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

add model

parent 0a66de78
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
This diff is collapsed.
cagnol.jpg

4.76 KiB

#Objective of this file is to analyse a face
import keras
import numpy as np
import cv2
from utils import *
emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
input_shape = (48,48,1)
def detectEmotion(face):
return "Happy?"
\ No newline at end of file
#Return the most likely emotion there is on a 48x48x1 gray face
#input = 48
face = normAndResize(face, input_shape)
model = keras.models.load_model('firstModel') #Load our model
emotionVect = predir(model, face)
emotionNbr = np.argmax(emotionVect)
emotion = emotions[emotionNbr]
return emotion
\ No newline at end of file
File added
File added
File added
#File to process images
import cv2
import numpy as np
import faceAnalysis as fa
input_shape = (48,48,1)
def imageProcess(image):
#Objectives : detect faces, identify emotion associated on it, modify the image by framing faces and writing their emotions associated
......@@ -31,6 +33,7 @@ def imageProcess(image):
#Write emotion on the image
emotion = fa.detectEmotion(face_color)
print(emotion)
cv2.putText(image, emotion, (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0), 2)
......@@ -51,3 +54,10 @@ def selectFace(image):
x,y,w,h = faces[0]
face = image[y:y+h, x:x+w]
return face
image = cv2.imread("cagnol.jpg", 1) #Load Cagnol colored image
imageProcess(image)
cv2.imshow("Cagnol", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
File added
File added
File added
import numpy as np
import cv2
def afficher(image):
if len(image.shape) == 3:
if image.shape[2] == 3: # (h,l,3)
......@@ -8,12 +11,14 @@ def afficher(image):
elif len(image.shape)== 2: # (h,l)
plt.imshow(image)
def predir():
pass
def predir(modele, image):
#Return output of image from modele
modele.predict(np.array([image]))[0,:]
def normAndResize(image):
def normAndResize(image, input_shape):
#For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it.
h,l,p = input_shape
image = cv2.resize(image, dsize=(h,l), interpolation=cv2.INTER_CUBIC) #resize for h and l #
if len(image.shape) == 3 and p==1 and image.shape[2] != 1 : #if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image)
image = image.mean(2)
......
......@@ -2,7 +2,7 @@
import cv2
import imageProcess as ip
cap = cv2.VideoCapture(-1) #0 means we capture the first camera, your webcam probably
cap = cv2.VideoCapture(0) #0 means we capture the first camera, your webcam probably
while cap.isOpened():
ret, frame = cap.read() #Read next video frame, stop if frame not well read
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment