Modification of the ROI (rectangle)
This commit is contained in:
parent
36b01581a6
commit
741b3138f7
|
|
@ -32,12 +32,19 @@ for i in range(num_frames):
|
||||||
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
# Detect faces
|
# 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
|
# Dessiner un rectangle autour de chaque visage détecté and if fac is detected store information
|
||||||
if len(faces) > 0:
|
if len(face) > 0:
|
||||||
x, y, w, h = faces[0]
|
x, y, w, h = face[0]
|
||||||
face = frame[y:y+h, x:x+w]
|
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
|
# Split into RGB channels
|
||||||
b, g, r = cv2.split(face)
|
b, g, r = cv2.split(face)
|
||||||
|
|
@ -49,7 +56,9 @@ for i in range(num_frames):
|
||||||
|
|
||||||
# Add to list
|
# Add to list
|
||||||
average_rgb.append([avg_b, avg_g, avg_r])
|
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
|
# Convert to numpy array
|
||||||
average_rgb = np.array(average_rgb)
|
average_rgb = np.array(average_rgb)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
# Charger le classificateur Haar Cascade
|
# Charger le classificateur Haar Cascade
|
||||||
face_cascade = cv2.CascadeClassifier("Haar_Cascade_Eye")
|
face_cascade = cv2.CascadeClassifier("Haar_Cascade.xml")
|
||||||
|
|
||||||
# Charger l'image dans OpenCV
|
# Charger l'image dans OpenCV
|
||||||
# Convertir l'image en niveaux de gris
|
# 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")
|
print("Error: input image is empty")
|
||||||
|
|
||||||
# Détection des visages dans l'image
|
# Détection des visages dans l'image
|
||||||
Eye = face_cascade.detectMultiScale(
|
face = face_cascade.detectMultiScale(gray_img, scaleFactor=1.1, minNeighbors=5)
|
||||||
gray_img, scaleFactor=1.1, minNeighbors=5)
|
print(face)
|
||||||
|
|
||||||
# Dessiner un rectangle autour de chaque visage détecté
|
# Dessiner un rectangle autour de chaque visage détecté
|
||||||
for x, y, w, h in Eye:
|
for x, y, w, h in face:
|
||||||
img = cv2.rectangle(img, (x, y),
|
img = cv2.rectangle(img, (int(x*1.15), int(y*1.1)),
|
||||||
(x + w, y + h), (0, 255, 0), 3)
|
(x + int(w*0.8), y + int(h*0.5)), (0, 255, 0), 3)
|
||||||
|
|
||||||
# Afficher l'image
|
# Afficher l'image
|
||||||
cv2.imshow("Faces", img)
|
cv2.imshow("Faces", img)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue