Total Program

This commit is contained in:
Alexandre VEROT 2023-02-08 21:44:59 +01:00
parent 1fa7fc2558
commit 36b01581a6
8 changed files with 12323 additions and 15 deletions

10
Calculation.m Normal file
View File

@ -0,0 +1,10 @@
img = imread('Image.jpg');
pixels = double(img);
raw_data = reshape(pixels, [], 1);
% We have to add an iteration for the RGB chanels
% To calculate the mean value
mean_value = mean(A);
% To calculate the standard deviation
standard_deviation = std(A);
% x'(t)=(x(t)-mean)/standard deviation
norm_data = (raw_data - mean_value)/standard_deviation;

8
CalculationTest.m Normal file
View File

@ -0,0 +1,8 @@
raw_data = [];
% We have to add an iteration for the RGB chanels
% To calculate the mean value
mean_value = mean(raw_data)
% To calculate the standard deviation
standard_deviation = std(raw_data)
% x'(t)=(x(t)-mean)/standard deviation
norm_data = (raw_data - mean_value)/standard_deviation

8
Calculation_2.m Normal file
View File

@ -0,0 +1,8 @@
raw_data = [1,2,3,4,5];
% We have to add an iteration for the RGB chanels
% To calculate the mean value
mean_value = mean(raw_data)
% To calculate the standard deviation
standard_deviation = std(raw_data)
% x'(t)=(x(t)-mean)/standard deviation
norm_data = (raw_data - mean_value)/standard_deviation

74
CompletedCode.py Normal file
View File

@ -0,0 +1,74 @@
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Load video using OpenCV
video = cv2.VideoCapture("PPG_Programming.mp4")
# Get video information
fps = video.get(cv2.CAP_PROP_FPS)
num_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
# Load face detection model
face_detector = cv2.CascadeClassifier("Haar_Cascade.xml")
# Lists to store information for each frame
frame_matrices = []
average_rgb = []
# Loop through frames
for i in range(num_frames):
ret, frame = video.read()
# Check if frame was successfully retrieved
if not ret:
break
# Skip frames to get 15 frames per second
if i % int(fps/15) != 0:
continue
# Convert to grayscale
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect faces
faces = face_detector.detectMultiScale(gray_frame, 1.3, 5)
# If face is detected, store information
if len(faces) > 0:
x, y, w, h = faces[0]
face = frame[y:y+h, x:x+w]
# Split into RGB channels
b, g, r = cv2.split(face)
# Calculate average on each channel
avg_b = np.mean(b) / 255
avg_g = np.mean(g) / 255
avg_r = np.mean(r) / 255
# Add to list
average_rgb.append([avg_b, avg_g, avg_r])
frame_matrices.append(face)
# Convert to numpy array
average_rgb = np.array(average_rgb)
# Get number of frames
num_frames = average_rgb.shape[0]
# Create an array of frame numbers
frame_numbers = np.arange(num_frames)
# Plot the line graph
plt.plot(frame_numbers, average_rgb[:, 0], 'b', label='Blue')
plt.plot(frame_numbers, average_rgb[:, 1], 'g', label='Green')
plt.plot(frame_numbers, average_rgb[:, 2], 'r', label='Red')
# Add labels and legend
plt.xlabel('Frame Number')
plt.ylabel('Normalized Average RGB Value')
plt.legend(loc='upper right')
# Show the plot
plt.show()

12213
Haar_Cascade_Eye Normal file

File diff suppressed because it is too large Load Diff

BIN
PPG_Programming.mp4 Normal file

Binary file not shown.

View File

@ -4,7 +4,7 @@ import cv2
import numpy as np
# Charger le classificateur Haar Cascade
face_cascade = cv2.CascadeClassifier("Haar_Cascade.xml")
face_cascade = cv2.CascadeClassifier("Haar_Cascade_Eye")
# Charger l'image dans OpenCV
# Convertir l'image en niveaux de gris
@ -15,23 +15,14 @@ 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
faces = face_cascade.detectMultiScale(
Eye = face_cascade.detectMultiScale(
gray_img, scaleFactor=1.1, minNeighbors=5)
# Dessiner un rectangle autour de chaque visage détecté
for x, y, w, h in faces:
img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 3)
for x, y, w, h in Eye:
img = cv2.rectangle(img, (x, y),
(x + w, y + h), (0, 255, 0), 3)
# Afficher l'image
cv2.imshow("Faces", img)
cv2.waitKey(0)
# Split the image into its RGB channels
b, g, r = cv2.split(img)
# Display the individual channels
cv2.imshow('Red channel', r)
cv2.imshow('Green channel', g)
cv2.imshow('Blue channel', b)
cv2.waitKey(0)
cv2.destroyAllWindows()

View File

@ -6,10 +6,14 @@ img = cv2.imread('Image.jpg')
# Split the image into its RGB channels
b, g, r = cv2.split(img)
# e = np.zeros((100, 100), dtype=np.uint8)
# red_merged = cv2.merge((e, e, r))
# Display the individual channels
cv2.imshow('Red channel', r)
# cv2.imshow('Red channel 2', red_merged)
cv2.imshow('Green channel', g)
cv2.imshow('Blue channel', b)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Note that the individual channels are displayed in grayscale because they represent the intensity values of a single color (red, green, or blue) in the image.