Compare commits

..

5 Commits

Author SHA1 Message Date
Julian LECLERC 65f25bb19d ROI analysis 2022-04-06 16:45:38 +02:00
Julian LECLERC 6a50638753 Camera Feed Area Of Intrest 2022-04-06 15:33:27 +02:00
Julian LECLERC cbb47880db cameraFeed2 2022-04-06 13:51:46 +02:00
Julian LECLERC efa66c4a71 CameraFeed 2022-04-06 12:15:41 +02:00
Julian LECLERC 1837834c83 Camera Development 1 2022-04-06 11:38:23 +02:00
6 changed files with 163 additions and 2 deletions

38
Camerafeed/Camerafeed.pde Normal file
View File

@ -0,0 +1,38 @@
import processing.video.*;
Capture cam;
int x =0;
int d = 26;
int eyeZone = 10;
float s = 1/30;
int start = 0;
void setup() {
size(750, 480);
cam = new Capture(this, width, height);
cam.start();
loop();
x=0;
}
void draw() {
if(cam.available()) {
cam.read();
}
image(cam, 0, 0);
if(x<10*1/s && start==1){
saveFrame("frame_#####.jpg");
x++;
}
//fill(255,0,0);
rect(width*0.5-d*2-eyeZone/2,height*0.5,eyeZone,5);
rect(width*0.5+d*2-eyeZone/2,height*0.5,eyeZone,5);
fill(0,0);
rect(width*0.5-3*d/2,height*0.5-d*5/2,3*d,3*d/2);
delay( int(s*1000) );
}
void keyPressed() {
start = 1;
println("ok");
}

34
Camerafeed/picToROI.m Normal file
View File

@ -0,0 +1,34 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function [] = ()
%
% Task:
%
% Inputs:
% Outputs:
%
% Antoine Rodary - Julian Leclerc - Gwenn Durpoix-Espinasson - Luc Pichot
% 06/04/2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [gROI] = picToROI(imgWidth,imgHeight,nbIm,d)
display("piToRoi Start")
files = dir('*.jpg');
ROI = zeros (3*d/2,3*d+1,nbIm,3);
for n=1:1:nbIm
files(n).name
frame = imread (files(n).name);
Image = im2double (frame);
for i=1:1:3*d/2 %imgHeight*0.5-d*5/2:1:3*d/2
for j=1:1:3*d %imgWidth*0.5-3*d/2:1:3*d
rROI(i,j,n) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,1)*255;
gROI(i,j,n) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,2)*255;
bROI(i,j,n) = Image(i+imgHeight*0.5-d*5/2,j+imgWidth*0.5-3*d/2,3)*255;
endfor
endfor
endfor
display("piToRoi End")
endfunction

43
Camerafeed/plotAverage.m Normal file
View File

@ -0,0 +1,43 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function []= plotAverage(ROI,nbIm, fps)
%
% Task: plotting the average color of the ROI over time
%
% Inputs:
% - ROI: 3D matrix, Region of interest, made out of 'nbIm' different images
% - nbIm: integer, number of images stored from the video
% - fps: frames per seconds of the video
%
% Outputs:
% - plot of the average color of the ROI as a function of time
%
% Antoine Rodary - Julian Leclerc - Gwenn Durpoix-Espinasson - Luc Pichot
% 06/04/2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [averageArray]= plotAverage(ROI,nbIm, fps)
display("PlotAv Start")
% passing through each image of the video
averageArray = zeros(1,nbIm);
[n,m,Nimg]=size(ROI);
for k = 1:nbIm
% calculating the average value of the ROI
sum = 0;
for i = 1:n
for j = 1:m
sum = sum + ROI(i,j,k);
end
end
average = sum/(i*j);
%storing
averageArray(k)= average;
end
xAxis = [0:(1/fps):(nbIm/fps)-(1/fps)];
figure(1);
plot(xAxis, averageArray);
title('Average color of the ROI over time')
xlabel('t (s)')
ylabel('Average color of the ROI')
display("PlotAv End")
endfunction

38
Camerafeed/plotFFT.m Normal file
View File

@ -0,0 +1,38 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function []= plotFFT(averageArray, nbIm, fps)
%
% Task: plotting the fast fourier transform of the average color of the ROI
%
% Inputs:
% - averageArray : function of the average color of the ROI over time
% - nbIm : integer, number of images stored from the video
% - fps : frames per seconds of the video
%
% Outputs:
% - plot of the fast fourier transform of the average color of the ROI
%
% Antoine Rodary - Julian Leclerc - Gwenn Durpoix-Espinasson - Luc Pichot
% 06/04/2021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function []= plotFFT(averageArray, nbIm,fps)
display("Plot FFT Start")
Fs = fps; % Sampling frequency
T = 1/Fs; % Sampling period
L = nbIm; % Length of signal
t = (0:L-1)*T; % Time vector
Y = fft(averageArray);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
figure(2);
plot(f,P1)
title('Fast Fourier Transform of the signal of the average color of the ROI')
xlabel('f (Hz)')
ylabel('|P1(f)|')
display("Plot FFT End")
hold on;
endfunction

10
Camerafeed/testfunction.m Normal file
View File

@ -0,0 +1,10 @@
fps = 30;
nbIm = 300;
%rROI = picToROI(750,480,nbIm,26,1);
gROI = picToROI(750,480,nbIm,26,1);
%bROI = picToROI(750,480,nbIm,26,1);
hold
averageArray = plotAverage(gROI,nbIm, fps);
plotFFT(averageArray, nbIm,fps);

View File

@ -1,2 +0,0 @@
This is the project based on PPG analysis made in the continuity of the Signal Processing course on the 6th of April 2022.
It includes all the algorithms used in order to read the heart rate of an individual from a video.