From 176ba23214c3888d30e7241d3eaf47897132808c Mon Sep 17 00:00:00 2001
From: Vaek <timothe.boulet@student-cs.fr>
Date: Thu, 18 Mar 2021 19:30:21 +0100
Subject: [PATCH] add selectFace

---
 imageProcess.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/imageProcess.py b/imageProcess.py
index df0530f..c2670e3 100644
--- a/imageProcess.py
+++ b/imageProcess.py
@@ -31,4 +31,23 @@ def imageProcess(image):
 
         #Write emotion on the image
         emotion = fa.detectEmotion(face_color)
-        cv2.putText(image, emotion, (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0), 2)
\ No newline at end of file
+        cv2.putText(image, emotion, (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0), 2)
+
+
+
+def selectFace(image):
+    #Return a face identified on an colored image
+
+    #Import cv2 face detector
+    face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+'haarcascade_frontalface_default.xml')
+
+    #Face detection is made on gray images
+    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
+
+    faces = face_cascade.detectMultiScale(gray, 1.3, 5) #This return a list of tuple locating faces on image
+    
+    #The face returned is the first face detected on the image (if exists)
+    if faces != []:
+        x,y,w,h = faces[0]
+        face = image[y:y+h, x:x+w]
+        return face
\ No newline at end of file
-- 
GitLab