Compare commits
No commits in common. "rgb_value" and "main" have entirely different histories.
10
README.md
|
|
@ -1,11 +1,3 @@
|
|||
# heatrateestimation
|
||||
|
||||
This file contains our work of the heart rate estimation of a person from a video.
|
||||
|
||||
## Python
|
||||
|
||||
The python will deal with the image extraction and will have to be run each time for new videos.
|
||||
|
||||
## Octave
|
||||
|
||||
The octave file will work on the bulk of the project to process the data.
|
||||
This file contains our work of the heart rate estimation of a person from a video.
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
############
|
||||
# frame extraction
|
||||
#
|
||||
# Task:
|
||||
|
|
@ -15,21 +16,4 @@
|
|||
# Author: Thomas Périn
|
||||
# Date: 17/02/2023
|
||||
#
|
||||
# Note: check video name when extracting a new one
|
||||
############
|
||||
|
||||
import cv2
|
||||
|
||||
#Select video by name
|
||||
vidcap = cv2.VideoCapture('face_video.mp4')
|
||||
success,image = vidcap.read()
|
||||
|
||||
#Counter to number the images
|
||||
count = 0
|
||||
|
||||
#Extraction loop for all images
|
||||
while success:
|
||||
cv2.imwrite("img%d.png" % count, image) # save frame as JPEG file
|
||||
success,image = vidcap.read()
|
||||
print('Read a new frame: ', success)
|
||||
count += 1
|
||||
|
|
@ -1,51 +1,53 @@
|
|||
%hr = heartRateEstimation(imgDirectory, fps, windowDuration, windowShift)
|
||||
%%%%%%%%%%%%%%%%%
|
||||
% hr = heartRateEstimation(imgDirectory, fps, windowDuration, windowShift)
|
||||
%
|
||||
% Task: Finding the heartrate of person from selcted images
|
||||
%
|
||||
% Task:
|
||||
%
|
||||
% Inputs:
|
||||
% -imgDirectory
|
||||
% -fps
|
||||
% -fps
|
||||
% -windowDuration
|
||||
% -windowShift
|
||||
%
|
||||
% Output:
|
||||
% -heartrate:
|
||||
% -hr:
|
||||
%
|
||||
% Author: Thomas Périn
|
||||
% Date: 17/02/2023
|
||||
% Author: Guillaume Gibert
|
||||
% Date: 06/02/2023
|
||||
%
|
||||
% Note: images were extracted with ffmpeg -i "video.mkv" ../img/gg_%04d.png
|
||||
%%%%%%%%%%%%%%%%%
|
||||
|
||||
clc
|
||||
clear all
|
||||
|
||||
% temp var
|
||||
fps = 15;
|
||||
%temp var
|
||||
imgDirectory = 'img';
|
||||
fps = 60;
|
||||
windowDuration = 30;
|
||||
roi = [280 580 600 850];
|
||||
windowShift = 1;
|
||||
roi = [225 750 825 1100];
|
||||
|
||||
% global
|
||||
% global
|
||||
redChannel = [];
|
||||
greenChannel = [];
|
||||
blueChannel = [];
|
||||
|
||||
%list the images with i the same directory
|
||||
listImg = dir(['*.png']);
|
||||
%list the images
|
||||
listImg = dir([imgDirectory '/*.png']);
|
||||
|
||||
% iteration for every images available
|
||||
for l_img=1:windowDuration*fps
|
||||
% load the current image
|
||||
image_original = imread([listImg(l_img).name]);
|
||||
|
||||
image_original = imread([imgDirectory '/' listImg(l_img).name]);
|
||||
%image(image_original);
|
||||
|
||||
% crop the current image around the face
|
||||
image_face = image_original(roi(1):roi(2), roi(3):roi(4), :);
|
||||
|
||||
%image(image_face);
|
||||
|
||||
% spatial average for r, g, b channels
|
||||
r_mean = mean(mean(image_face(:,:,1)));
|
||||
g_mean = mean(mean(image_face(:,:,2)));
|
||||
b_mean = mean(mean(image_face(:,:,3)));
|
||||
|
||||
|
||||
% store the current "average" pixel in global arrays
|
||||
redChannel = [redChannel r_mean];
|
||||
greenChannel = [greenChannel g_mean];
|
||||
|
|
@ -53,39 +55,26 @@ for l_img=1:windowDuration*fps
|
|||
end
|
||||
|
||||
% estimate temporal average and standard deviation
|
||||
redChannel_avg = mean(redChannel);
|
||||
redChannel_std = std(redChannel);
|
||||
greenChannel_avg = mean(greenChannel);
|
||||
greenChannel_std = std(greenChannel);
|
||||
blueChannel_avg = mean(blueChannel);
|
||||
blueChannel_std = std(blueChannel);
|
||||
|
||||
% normalize your data
|
||||
% first define length of our data
|
||||
L = columns(greenChannel);
|
||||
for i=1:L
|
||||
greenChannel_normalized(i) = (greenChannel(i) - greenChannel_avg)/greenChannel_std;
|
||||
end
|
||||
% normalize your data
|
||||
% greenChannel_normalized(i) = (greenChannel(i) - greenChannel_avg)/greenChannel_std
|
||||
|
||||
% select only greenChannel for simplicity (no ICA)
|
||||
greenChannel_fft = fft(greenChannel_normalized);
|
||||
% fft(greenChannel_normalized)
|
||||
|
||||
% power spectrum using link(https://www.mathworks.com/help/matlab/ref/fft.html)
|
||||
P2 = abs(greenChannel_fft/L);
|
||||
P1 = P2(1:L/2+1);
|
||||
P1(2:end-1) = 2*P1(2:end-1);
|
||||
f = 15*(0:(L/2))/L;
|
||||
plot(f,P1)
|
||||
% power spectrum (https://www.mathworks.com/help/matlab/ref/fft.html)
|
||||
|
||||
% find the peak in the range ([0.75 4] Hz)
|
||||
% define range and round to get intergers
|
||||
low_index = round(0.75*L/15);
|
||||
high_index = round(2*L/15);
|
||||
% find max value and index inn new range
|
||||
[a, ia] = max(P1(low_index:high_index));
|
||||
% adapt the index for full range
|
||||
heart_frequency = f(ia+low_index)
|
||||
% max -> value, index
|
||||
|
||||
% convert the index from Hz to bpm
|
||||
|
||||
% determine heart rate
|
||||
% convert the index from Hz to bpm
|
||||
heart_rate = heart_frequency*60
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
BIN
img100.png
|
Before Width: | Height: | Size: 731 KiB |
BIN
img101.png
|
Before Width: | Height: | Size: 733 KiB |
BIN
img102.png
|
Before Width: | Height: | Size: 736 KiB |
BIN
img103.png
|
Before Width: | Height: | Size: 739 KiB |
BIN
img104.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img105.png
|
Before Width: | Height: | Size: 737 KiB |
BIN
img106.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img107.png
|
Before Width: | Height: | Size: 738 KiB |
BIN
img108.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img109.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img110.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img111.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img112.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img113.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img114.png
|
Before Width: | Height: | Size: 744 KiB |
BIN
img115.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img116.png
|
Before Width: | Height: | Size: 746 KiB |
BIN
img117.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img118.png
|
Before Width: | Height: | Size: 744 KiB |
BIN
img119.png
|
Before Width: | Height: | Size: 746 KiB |
BIN
img120.png
|
Before Width: | Height: | Size: 656 KiB |
BIN
img121.png
|
Before Width: | Height: | Size: 738 KiB |
BIN
img122.png
|
Before Width: | Height: | Size: 766 KiB |
BIN
img123.png
|
Before Width: | Height: | Size: 776 KiB |
BIN
img124.png
|
Before Width: | Height: | Size: 782 KiB |
BIN
img125.png
|
Before Width: | Height: | Size: 780 KiB |
BIN
img126.png
|
Before Width: | Height: | Size: 780 KiB |
BIN
img127.png
|
Before Width: | Height: | Size: 784 KiB |
BIN
img128.png
|
Before Width: | Height: | Size: 785 KiB |
BIN
img129.png
|
Before Width: | Height: | Size: 782 KiB |
BIN
img130.png
|
Before Width: | Height: | Size: 782 KiB |
BIN
img131.png
|
Before Width: | Height: | Size: 782 KiB |
BIN
img132.png
|
Before Width: | Height: | Size: 786 KiB |
BIN
img133.png
|
Before Width: | Height: | Size: 784 KiB |
BIN
img134.png
|
Before Width: | Height: | Size: 786 KiB |
BIN
img135.png
|
Before Width: | Height: | Size: 783 KiB |
BIN
img136.png
|
Before Width: | Height: | Size: 734 KiB |
BIN
img137.png
|
Before Width: | Height: | Size: 733 KiB |
BIN
img138.png
|
Before Width: | Height: | Size: 739 KiB |
BIN
img139.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img140.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img141.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img142.png
|
Before Width: | Height: | Size: 744 KiB |
BIN
img143.png
|
Before Width: | Height: | Size: 745 KiB |
BIN
img144.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img145.png
|
Before Width: | Height: | Size: 744 KiB |
BIN
img146.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img147.png
|
Before Width: | Height: | Size: 739 KiB |
BIN
img148.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img149.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img150.png
|
Before Width: | Height: | Size: 657 KiB |
BIN
img151.png
|
Before Width: | Height: | Size: 738 KiB |
BIN
img152.png
|
Before Width: | Height: | Size: 714 KiB |
BIN
img153.png
|
Before Width: | Height: | Size: 724 KiB |
BIN
img154.png
|
Before Width: | Height: | Size: 733 KiB |
BIN
img155.png
|
Before Width: | Height: | Size: 736 KiB |
BIN
img156.png
|
Before Width: | Height: | Size: 737 KiB |
BIN
img157.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img158.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img159.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img160.png
|
Before Width: | Height: | Size: 741 KiB |
BIN
img161.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img162.png
|
Before Width: | Height: | Size: 744 KiB |
BIN
img163.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img164.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img165.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img166.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img167.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img168.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img169.png
|
Before Width: | Height: | Size: 739 KiB |
BIN
img170.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img171.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img172.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img173.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img174.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img175.png
|
Before Width: | Height: | Size: 738 KiB |
BIN
img176.png
|
Before Width: | Height: | Size: 739 KiB |
BIN
img177.png
|
Before Width: | Height: | Size: 743 KiB |
BIN
img178.png
|
Before Width: | Height: | Size: 742 KiB |
BIN
img179.png
|
Before Width: | Height: | Size: 740 KiB |
BIN
img180.png
|
Before Width: | Height: | Size: 654 KiB |
BIN
img181.png
|
Before Width: | Height: | Size: 738 KiB |
BIN
img182.png
|
Before Width: | Height: | Size: 763 KiB |
BIN
img183.png
|
Before Width: | Height: | Size: 775 KiB |
BIN
img184.png
|
Before Width: | Height: | Size: 779 KiB |
BIN
img185.png
|
Before Width: | Height: | Size: 779 KiB |