Merge branch 'develop'
This commit is contained in:
commit
1e91841ba7
|
|
@ -84,10 +84,15 @@ def average_and_export():
|
|||
image = "frames/frame" + str(i) + ".jpg"
|
||||
read_img = cv2.imread(image)
|
||||
#Bug here inside of func with min funcs of empty data
|
||||
<<<<<<< HEAD
|
||||
try:
|
||||
out_colors = RGB_dataframe(read_img, i)
|
||||
except:
|
||||
out_colors = out_colors
|
||||
=======
|
||||
|
||||
out_colors = RGB_dataframe(read_img, i)
|
||||
>>>>>>> develop
|
||||
Ravg = sum(out_colors[0])/len(out_colors[0])
|
||||
Gavg = sum(out_colors[1])/len(out_colors[1])
|
||||
Bavg = sum(out_colors[2])/len(out_colors[2])
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
%%%%%%%%%%%%%%%%%%%%%
|
||||
% function RGB_avg = RGB_traces (input1)
|
||||
% ex. RGB_avgs = 2DRotationMatrix('frame0.jpg')
|
||||
%
|
||||
% Task: Extracting the average RGB values of a frame
|
||||
%
|
||||
% Inputs:
|
||||
% - input1: frame adress on pc
|
||||
%
|
||||
% Output:
|
||||
% -RGB_avg: a 1x3 matrix with the RGB average values, format -> [R, G, B]
|
||||
%
|
||||
% author: Loic Delattre (loic.delattre@ecam.fr)
|
||||
% date: 06/02/2023
|
||||
%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
function RGB_avg = RGB_traces (image)
|
||||
I = imread (image);
|
||||
RGB_avg = [];
|
||||
i = 3;
|
||||
j = 1;
|
||||
while i >= 1
|
||||
RGB_avg(j) = matrix_avg (I(:,:,i));
|
||||
j = j + 1;
|
||||
i = i - 1;
|
||||
endwhile
|
||||
endfunction
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
%%%%%%%%%%%%%%%%%%%%%
|
||||
% function RGB_avg = RGB_traces (input1)
|
||||
% ex. RGB_avgs = 2DRotationMatrix('frame0.jpg')
|
||||
%
|
||||
% Task: Extracting the average RGB values of a frame
|
||||
%
|
||||
% Inputs:
|
||||
% - input1: frame adress on pc
|
||||
%
|
||||
% Output:
|
||||
% -RGB_avg: a 1x3 matrix with the RGB average values, format -> [R, G, B]
|
||||
%
|
||||
% author: Loic Delattre (loic.delattre@ecam.fr)
|
||||
% date: 06/02/2023
|
||||
%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
function RGB_data = frames_RGBs ()
|
||||
%frames_num = 918;
|
||||
j = 0;
|
||||
RGB_data = [0, 0, 0];
|
||||
while j <= 10000
|
||||
try
|
||||
image = strcat('frames/frame', int2str(j), '.jpg');
|
||||
j = j + 1;
|
||||
i = 3;
|
||||
while i >= 1
|
||||
RGB_data(i, j) = RGB_traces (image)(i);
|
||||
i = i - 1;
|
||||
endwhile
|
||||
catch
|
||||
disp('scanned all frames')
|
||||
j = 10001
|
||||
end_try_catch
|
||||
endwhile
|
||||
|
||||
endfunction
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import cv2
|
||||
import os.path
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
# Opens the Video file
|
||||
video = 'my_face.mov'
|
||||
|
|
@ -11,14 +12,57 @@ if os.path.exists(path_to_script + r"\frames") == False:
|
|||
def get_frames(vid):
|
||||
cap= cv2.VideoCapture(vid)
|
||||
i=0
|
||||
while(cap.isOpened()):
|
||||
ret, frame = cap.read()
|
||||
while cap.isOpened():
|
||||
ret, img = cap.read()
|
||||
if ret == False:
|
||||
break
|
||||
cv2.imwrite('frames/frame'+str(i)+'.jpg',frame)
|
||||
i+=1
|
||||
|
||||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||||
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
|
||||
|
||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
||||
|
||||
for (x,y,w,h) in faces:
|
||||
# To draw a rectangle in a face
|
||||
cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2)
|
||||
roi_gray = gray[y:y+h, x:x+w]
|
||||
roi_color = img[y:y+h, x:x+w]
|
||||
|
||||
eyes = eye_cascade.detectMultiScale(roi_gray)
|
||||
list_ex = []
|
||||
list_ey = []
|
||||
list_ew = []
|
||||
list_eh = []
|
||||
|
||||
#To draw a rectangle in eyes
|
||||
for (ex,ey,ew,eh) in eyes:
|
||||
if ew >= 80 and eh >= 80:
|
||||
#cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2)
|
||||
list_ex.append(ex)
|
||||
list_ey.append(ey)
|
||||
list_ew.append(ew)
|
||||
list_eh.append(eh)
|
||||
|
||||
#rectangle on forhead
|
||||
try:
|
||||
fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))]
|
||||
fy = max(list_ey)
|
||||
x1 = x + fx
|
||||
x2 = x + fx + 100
|
||||
y1 = y + fy - 150
|
||||
y2 = y + fy - 20
|
||||
|
||||
imRGB = img[y1:y2, x1:x2]
|
||||
|
||||
cv2.imwrite('frames/frame'+str(i)+'.jpg',imRGB)
|
||||
i+=1
|
||||
except:
|
||||
print('error on min value of ex')
|
||||
#extra values in x and y in the parameters are adjustements made after manual testing
|
||||
#cv2.rectangle(roi_color, (fx,fy-150),(fx+100,fy-20),(0,127,255),2)
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
returnx
|
||||
get_frames(video)
|
||||
return i
|
||||
print('number of frames extracted ' + get_frames(video))
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
%%%%%%%%%%%%%%%%%%%%%
|
||||
% function RGB_avg = RGB_traces (input1)
|
||||
% ex. RGB_avgs = 2DRotationMatrix('frame0.jpg')
|
||||
%
|
||||
% Task: Extracting the average RGB values of a frame
|
||||
%
|
||||
% Inputs:
|
||||
% - input1: frame adress on pc
|
||||
%
|
||||
% Output:
|
||||
% -RGB_avg: a 1x3 matrix with the RGB average values
|
||||
%
|
||||
% author: Loic Delattre (loic.delattre@ecam.fr)
|
||||
% date: 06/02/2023
|
||||
%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
function Mavg = matrix_avg (M)
|
||||
col = size(M,2);
|
||||
row = size(M,1);
|
||||
num_items = col*row;
|
||||
Mavg = sum(sum(M))/num_items;
|
||||
endfunction
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
clear all
|
||||
close all
|
||||
clc
|
||||
|
||||
threshold = 1e-6;
|
||||
|
||||
RGB_data = frames_RGBs ();
|
||||
|
||||
%TEST 1
|
||||
%Average of all the items inside of a matrix
|
||||
A = [1, 2; 3, 4];
|
||||
avg = 2.5;
|
||||
if matrix_avg (A) - avg < threshold
|
||||
disp('Test 1 passed gg')
|
||||
else
|
||||
disp('Test 1 failed, f')
|
||||
endif
|
||||
Loading…
Reference in New Issue