From 741b3138f7d398301090f18275e7c0c01c3d9303 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Wed, 8 Feb 2023 22:21:04 +0100 Subject: [PATCH] Modification of the ROI (rectangle) --- CompletedCode.py | 19 ++++++++++++++----- ProgrammingForFaceDetection.py | 13 ++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CompletedCode.py b/CompletedCode.py index 6231fad..2f92c1c 100644 --- a/CompletedCode.py +++ b/CompletedCode.py @@ -32,12 +32,19 @@ for i in range(num_frames): gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Detect faces - faces = face_detector.detectMultiScale(gray_frame, 1.3, 5) + face = face_detector.detectMultiScale( + gray_frame, scaleFactor=1.1, minNeighbors=5) + # print(face) - # If face is detected, store information - if len(faces) > 0: - x, y, w, h = faces[0] + # Dessiner un rectangle autour de chaque visage détecté and if fac is detected store information + if len(face) > 0: + x, y, w, h = face[0] face = frame[y:y+h, x:x+w] + frame = cv2.rectangle(frame, (int(x*1.15), y), + (x + int(w*0.7), y + h), (0, 255, 0), 3) + # Afficher l'image + # cv2.imshow("Faces", frame) + # cv2.waitKey(0) # Split into RGB channels b, g, r = cv2.split(face) @@ -49,7 +56,9 @@ for i in range(num_frames): # Add to list average_rgb.append([avg_b, avg_g, avg_r]) - frame_matrices.append(face) + # frame_matrices.append(face) + print(average_rgb) + # print(frame_matrices) # Convert to numpy array average_rgb = np.array(average_rgb) diff --git a/ProgrammingForFaceDetection.py b/ProgrammingForFaceDetection.py index f364f67..4ab9883 100644 --- a/ProgrammingForFaceDetection.py +++ b/ProgrammingForFaceDetection.py @@ -4,7 +4,7 @@ import cv2 import numpy as np # Charger le classificateur Haar Cascade -face_cascade = cv2.CascadeClassifier("Haar_Cascade_Eye") +face_cascade = cv2.CascadeClassifier("Haar_Cascade.xml") # Charger l'image dans OpenCV # Convertir l'image en niveaux de gris @@ -15,13 +15,12 @@ if gray_img.shape[0] == 0 or gray_img.shape[1] == 0: print("Error: input image is empty") # Détection des visages dans l'image -Eye = face_cascade.detectMultiScale( - gray_img, scaleFactor=1.1, minNeighbors=5) - +face = face_cascade.detectMultiScale(gray_img, scaleFactor=1.1, minNeighbors=5) +print(face) # Dessiner un rectangle autour de chaque visage détecté -for x, y, w, h in Eye: - img = cv2.rectangle(img, (x, y), - (x + w, y + h), (0, 255, 0), 3) +for x, y, w, h in face: + img = cv2.rectangle(img, (int(x*1.15), int(y*1.1)), + (x + int(w*0.8), y + int(h*0.5)), (0, 255, 0), 3) # Afficher l'image cv2.imshow("Faces", img)