Compare commits

...

6 Commits

496 changed files with 74 additions and 39 deletions

View File

@ -1,3 +1,11 @@
# heatrateestimation # heatrateestimation
This file contains our work of the heart rate estimation of a person from a video. 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.

View File

@ -1,4 +1,3 @@
############
# frame extraction # frame extraction
# #
# Task: # Task:
@ -16,4 +15,21 @@
# Author: Thomas Périn # Author: Thomas Périn
# Date: 17/02/2023 # 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

View File

@ -1,53 +1,51 @@
%hr = heartRateEstimation(imgDirectory, fps, windowDuration, windowShift) %hr = heartRateEstimation(imgDirectory, fps, windowDuration, windowShift)
%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
% hr = heartRateEstimation(imgDirectory, fps, windowDuration, windowShift) % hr = heartRateEstimation(imgDirectory, fps, windowDuration, windowShift)
% %
% Task: % Task: Finding the heartrate of person from selcted images
% %
% Inputs: % Inputs:
% -imgDirectory % -imgDirectory
% -fps % -fps
% -windowDuration
% -windowShift
% %
% Output: % Output:
% -hr: % -heartrate:
% %
% Author: Guillaume Gibert % Author: Thomas Périn
% Date: 06/02/2023 % Date: 17/02/2023
% %
% Note: images were extracted with ffmpeg -i "video.mkv" ../img/gg_%04d.png % Note: images were extracted with ffmpeg -i "video.mkv" ../img/gg_%04d.png
%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
%temp var clc
imgDirectory = 'img'; clear all
fps = 60;
windowDuration = 30;
windowShift = 1;
roi = [225 750 825 1100];
% global % temp var
fps = 15;
windowDuration = 30;
roi = [280 580 600 850];
% global
redChannel = []; redChannel = [];
greenChannel = []; greenChannel = [];
blueChannel = []; blueChannel = [];
%list the images %list the images with i the same directory
listImg = dir([imgDirectory '/*.png']); listImg = dir(['*.png']);
% iteration for every images available
for l_img=1:windowDuration*fps for l_img=1:windowDuration*fps
% load the current image % load the current image
image_original = imread([imgDirectory '/' listImg(l_img).name]); image_original = imread([listImg(l_img).name]);
%image(image_original);
% crop the current image around the face % crop the current image around the face
image_face = image_original(roi(1):roi(2), roi(3):roi(4), :); image_face = image_original(roi(1):roi(2), roi(3):roi(4), :);
%image(image_face);
% spatial average for r, g, b channels % spatial average for r, g, b channels
r_mean = mean(mean(image_face(:,:,1))); r_mean = mean(mean(image_face(:,:,1)));
g_mean = mean(mean(image_face(:,:,2))); g_mean = mean(mean(image_face(:,:,2)));
b_mean = mean(mean(image_face(:,:,3))); b_mean = mean(mean(image_face(:,:,3)));
% store the current "average" pixel in global arrays % store the current "average" pixel in global arrays
redChannel = [redChannel r_mean]; redChannel = [redChannel r_mean];
greenChannel = [greenChannel g_mean]; greenChannel = [greenChannel g_mean];
@ -55,26 +53,39 @@ for l_img=1:windowDuration*fps
end end
% estimate temporal average and standard deviation % estimate temporal average and standard deviation
redChannel_avg = mean(redChannel);
redChannel_std = std(redChannel);
greenChannel_avg = mean(greenChannel); greenChannel_avg = mean(greenChannel);
greenChannel_std = std(greenChannel); greenChannel_std = std(greenChannel);
blueChannel_avg = mean(blueChannel);
blueChannel_std = std(blueChannel);
% normalize your data % normalize your data
% greenChannel_normalized(i) = (greenChannel(i) - greenChannel_avg)/greenChannel_std % first define length of our data
L = columns(greenChannel);
for i=1:L
greenChannel_normalized(i) = (greenChannel(i) - greenChannel_avg)/greenChannel_std;
end
% fft(greenChannel_normalized) % select only greenChannel for simplicity (no ICA)
greenChannel_fft = fft(greenChannel_normalized);
% power spectrum (https://www.mathworks.com/help/matlab/ref/fft.html) % 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)
% find the peak in the range ([0.75 4] Hz) % find the peak in the range ([0.75 4] Hz)
% max -> value, index % define range and round to get intergers
low_index = round(0.75*L/15);
% convert the index from Hz to bpm 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)
% determine heart rate % determine heart rate
% convert the index from Hz to bpm
heart_rate = heart_frequency*60

BIN
img0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 KiB

BIN
img1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 KiB

BIN
img10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
img100.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 KiB

BIN
img101.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 KiB

BIN
img102.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 KiB

BIN
img103.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

BIN
img104.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img105.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 KiB

BIN
img106.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img107.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
img108.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img109.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img110.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img111.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img112.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img113.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img114.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

BIN
img115.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img116.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 KiB

BIN
img117.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img118.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

BIN
img119.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 KiB

BIN
img12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img120.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 KiB

BIN
img121.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
img122.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 KiB

BIN
img123.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 KiB

BIN
img124.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 KiB

BIN
img125.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 KiB

BIN
img126.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 KiB

BIN
img127.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 KiB

BIN
img128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 KiB

BIN
img129.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 KiB

BIN
img13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img130.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 KiB

BIN
img131.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 KiB

BIN
img132.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 KiB

BIN
img133.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 KiB

BIN
img134.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 KiB

BIN
img135.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 KiB

BIN
img136.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 KiB

BIN
img137.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 KiB

BIN
img138.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

BIN
img139.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

BIN
img140.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img141.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img142.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

BIN
img143.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 KiB

BIN
img144.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img145.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

BIN
img146.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img147.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

BIN
img148.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img149.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img150.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 KiB

BIN
img151.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
img152.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 KiB

BIN
img153.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 KiB

BIN
img154.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 KiB

BIN
img155.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 KiB

BIN
img156.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 KiB

BIN
img157.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img158.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img159.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img160.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 KiB

BIN
img161.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img162.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 KiB

BIN
img163.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img164.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img165.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img166.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img167.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img168.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img169.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

BIN
img17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img170.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img171.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img172.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img173.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img174.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img175.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
img176.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

BIN
img177.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img178.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 KiB

BIN
img179.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

BIN
img18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 KiB

BIN
img180.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 KiB

BIN
img181.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

BIN
img182.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 KiB

BIN
img183.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 KiB

BIN
img184.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 KiB

BIN
img185.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 KiB

Some files were not shown because too many files have changed in this diff Show More