From 7254efbccefc2f4bb2b76e6cc3d984b029870ed8 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 13:55:00 +0100 Subject: [PATCH 01/17] removing all that can be done in Octave :( --- get_frames.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/get_frames.py b/get_frames.py index 7786e73..fb1b418 100644 --- a/get_frames.py +++ b/get_frames.py @@ -1,6 +1,7 @@ import cv2 import os.path import os +from PIL import Image # Opens the Video file video = 'my_face.mov' @@ -15,6 +16,40 @@ def get_frames(vid): ret, frame = cap.read() if ret == False: break + + 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 + fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))] + fy = max(list_ey) + #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) + cv2.imwrite('frames/frame'+str(i)+'.jpg',frame) i+=1 From f86a111048002fcc12eb17f8d7d555154dfb972a Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 13:55:46 +0100 Subject: [PATCH 02/17] removing all that can be done in Octave :( --- RGB_channels.py | 94 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/RGB_channels.py b/RGB_channels.py index fc908dc..4d22594 100644 --- a/RGB_channels.py +++ b/RGB_channels.py @@ -4,10 +4,34 @@ import csv import os import os.path +<<<<<<< Updated upstream #create a directory to store the RGB datas ouptut path_to_script = os.path.dirname(os.path.abspath(__file__)) if os.path.exists(path_to_script + r"\RGB database") == False: os.mkdir(path_to_script + r"\RGB database") +======= +############################ +# Task: Initating local files +# +# Input: +# - None +# +# Output: +# - Empty directories to store the RGB data, number of frames stored +# +# author: Delattre Loic, Dey Maryne (loic.delattre@ecam.fr, maryne.dey@ecam.fr) +# date: 06/02/2023 +######################## + +def rep_files_init(): + #create a directory to store the RGB datas ouptut + path_to_script = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(path_to_script + r"\RGB_database") == False: + os.mkdir(path_to_script + r"\RGB_database") + + onlyfiles = next(os.walk(path_to_script + r"\frames"))[2] #get the amount of frames previously extracted + frames_num = len(onlyfiles)-1 +>>>>>>> Stashed changes onlyfiles = next(os.walk(path_to_script + r"\frames"))[2] #get the amount of frames previously extracted frames_num = len(onlyfiles)-1 @@ -21,7 +45,27 @@ read_img = cv2.imread(image) #cv2.waitKey(0) +############################ +# Task: Extracting the RGB values from every pixel in a given frame +# +# Input: +# - A frame of the face video, the frame number +# +# Output: +# - Three lists containing all of the RGB values of the specific frame +# +# author: Delattre Loic, Dey Maryne (loic.delattre@ecam.fr, maryne.dey@ecam.fr) +# date: 06/02/2023 +######################## + def RGB_dataframe(img, itr): +<<<<<<< Updated upstream +======= + img = cv2.imread(image) + face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') + eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') + +>>>>>>> Stashed changes gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) @@ -52,7 +96,7 @@ def RGB_dataframe(img, itr): #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) - imS = cv2.resize(img, (960, 540)) + '''imS = cv2.resize(img, (960, 540)) #cv2.imshow('img',imS) #cv2.waitKey(0) x1 = x + fx @@ -69,14 +113,60 @@ def RGB_dataframe(img, itr): for i in range(0, size_list[0]): for j in range(0, size_list[1]): k = imRGB[i,j] +<<<<<<< Updated upstream pixel_values.append(k) fields = ['R', 'G', 'B'] with open('RGB database/RGB' + str(itr) + '_data.csv', 'w', newline="") as f: +======= + R.append(k[0]) + G.append(k[1]) + B.append(k[2])''' + + return R, G, B + +############################ +# Task: Exporting to a csv file the RGB traces averages of all the frame of a given video +# +# Input: +# - a folder with all the frames of one video +# +# Output: +# - One CSV with all RGB average dats +# +# author: Delattre Loic, Dey Maryne (loic.delattre@ecam.fr, maryne.dey@ecam.fr) +# date: 06/02/2023 +######################## + +def average_and_export(): + i = 0 + count = 0.1 + pixel_values = [] + frames_num = rep_files_init() + while i < frames_num: + i += 1 + image = "frames/frame" + str(i) + ".jpg" + #Bug here inside of func with min funcs of empty data + try: + out_colors = RGB_dataframe(image, i) + except: + out_colors = out_colors + 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]) + pixel_values.append([Ravg, Gavg, Bavg]) + if i/frames_num >= count: + print(str(round(count*100))+ "% of the database exported to csv") + count += 0.1 + + with open('RGB database/RGB_data.csv', 'w', newline="") as f: + fields = ['R', 'G', 'B'] +>>>>>>> Stashed changes write = csv.writer(f) write.writerow(fields) write.writerows(pixel_values) return +<<<<<<< Updated upstream i = 0 count = 0.1 while i < frames_num: @@ -85,3 +175,5 @@ while i < frames_num: if i/frames_num >= count: print(str(round(count*100))+ "% of the database exported to csv") count += 0.1 +======= +>>>>>>> Stashed changes From f95730b96de3bde5dec952bc63fa9a6c494ba019 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:11:59 +0100 Subject: [PATCH 03/17] extracts ROI frames from video --- get_frames.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/get_frames.py b/get_frames.py index fb1b418..25b04fb 100644 --- a/get_frames.py +++ b/get_frames.py @@ -6,14 +6,14 @@ from PIL import Image # Opens the Video file video = 'my_face.mov' path_to_script = os.path.dirname(os.path.abspath(__file__)) -if os.path.exists(path_to_script + r"\frames") == False: - os.mkdir(path_to_script + r"\frames") +if os.path.exists(path_to_script + r"\frames_testing") == False: + os.mkdir(path_to_script + r"\frames_testing") def get_frames(vid): cap= cv2.VideoCapture(vid) i=0 - while(cap.isOpened()): - ret, frame = cap.read() + while i<10: + ret, img = cap.read() if ret == False: break @@ -48,12 +48,18 @@ def get_frames(vid): fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))] fy = max(list_ey) #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) + #cv2.rectangle(roi_color, (fx,fy-150),(fx+100,fy-20),(0,127,255),2) + x1 = x + fx + x2 = x + fx + 100 + y1 = y + fy - 150 + y2 = y + fy - 20 - cv2.imwrite('frames/frame'+str(i)+'.jpg',frame) + imRGB = img[y1:y2, x1:x2] + + cv2.imwrite('frames_testing/frame'+str(i)+'.jpg',imRGB) i+=1 cap.release() cv2.destroyAllWindows() - returnx + return get_frames(video) \ No newline at end of file From 0bdea5985061385e5f26aecf092a80c0c4211b5f Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:18:35 +0100 Subject: [PATCH 04/17] unchanged from main --- RGB_channels.py | 97 ++++++------------------------------------------- 1 file changed, 12 insertions(+), 85 deletions(-) diff --git a/RGB_channels.py b/RGB_channels.py index 4d22594..efdfbc9 100644 --- a/RGB_channels.py +++ b/RGB_channels.py @@ -1,71 +1,24 @@ import cv2 -from PIL import Image import csv import os import os.path -<<<<<<< Updated upstream -#create a directory to store the RGB datas ouptut -path_to_script = os.path.dirname(os.path.abspath(__file__)) -if os.path.exists(path_to_script + r"\RGB database") == False: - os.mkdir(path_to_script + r"\RGB database") -======= -############################ -# Task: Initating local files -# -# Input: -# - None -# -# Output: -# - Empty directories to store the RGB data, number of frames stored -# -# author: Delattre Loic, Dey Maryne (loic.delattre@ecam.fr, maryne.dey@ecam.fr) -# date: 06/02/2023 -######################## - def rep_files_init(): #create a directory to store the RGB datas ouptut path_to_script = os.path.dirname(os.path.abspath(__file__)) - if os.path.exists(path_to_script + r"\RGB_database") == False: - os.mkdir(path_to_script + r"\RGB_database") + if os.path.exists(path_to_script + r"\RGB database") == False: + os.mkdir(path_to_script + r"\RGB database") onlyfiles = next(os.walk(path_to_script + r"\frames"))[2] #get the amount of frames previously extracted frames_num = len(onlyfiles)-1 ->>>>>>> Stashed changes -onlyfiles = next(os.walk(path_to_script + r"\frames"))[2] #get the amount of frames previously extracted -frames_num = len(onlyfiles)-1 + return frames_num -face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') -eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') -image = "frames/frame1.jpg" -read_img = cv2.imread(image) - -#cv2.imshow('img',imRGB) -#cv2.waitKey(0) - - -############################ -# Task: Extracting the RGB values from every pixel in a given frame -# -# Input: -# - A frame of the face video, the frame number -# -# Output: -# - Three lists containing all of the RGB values of the specific frame -# -# author: Delattre Loic, Dey Maryne (loic.delattre@ecam.fr, maryne.dey@ecam.fr) -# date: 06/02/2023 -######################## def RGB_dataframe(img, itr): -<<<<<<< Updated upstream -======= - img = cv2.imread(image) face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') ->>>>>>> Stashed changes gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) @@ -96,7 +49,7 @@ def RGB_dataframe(img, itr): #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) - '''imS = cv2.resize(img, (960, 540)) + imS = cv2.resize(img, (960, 540)) #cv2.imshow('img',imS) #cv2.waitKey(0) x1 = x + fx @@ -108,35 +61,19 @@ def RGB_dataframe(img, itr): #cv2.imshow('img',imRGB) #cv2.waitKey(0) + R = [] + G = [] + B = [] size_list = list(imRGB.shape[:2]) pixel_values = [] for i in range(0, size_list[0]): for j in range(0, size_list[1]): k = imRGB[i,j] -<<<<<<< Updated upstream - pixel_values.append(k) - fields = ['R', 'G', 'B'] - with open('RGB database/RGB' + str(itr) + '_data.csv', 'w', newline="") as f: -======= R.append(k[0]) G.append(k[1]) - B.append(k[2])''' - + B.append(k[2]) return R, G, B -############################ -# Task: Exporting to a csv file the RGB traces averages of all the frame of a given video -# -# Input: -# - a folder with all the frames of one video -# -# Output: -# - One CSV with all RGB average dats -# -# author: Delattre Loic, Dey Maryne (loic.delattre@ecam.fr, maryne.dey@ecam.fr) -# date: 06/02/2023 -######################## - def average_and_export(): i = 0 count = 0.1 @@ -145,9 +82,10 @@ def average_and_export(): while i < frames_num: i += 1 image = "frames/frame" + str(i) + ".jpg" + read_img = cv2.imread(image) #Bug here inside of func with min funcs of empty data try: - out_colors = RGB_dataframe(image, i) + out_colors = RGB_dataframe(read_img, i) except: out_colors = out_colors Ravg = sum(out_colors[0])/len(out_colors[0]) @@ -160,20 +98,9 @@ def average_and_export(): with open('RGB database/RGB_data.csv', 'w', newline="") as f: fields = ['R', 'G', 'B'] ->>>>>>> Stashed changes write = csv.writer(f) write.writerow(fields) write.writerows(pixel_values) - return + return -<<<<<<< Updated upstream -i = 0 -count = 0.1 -while i < frames_num: - i += 1 - RGB_dataframe(read_img, i) - if i/frames_num >= count: - print(str(round(count*100))+ "% of the database exported to csv") - count += 0.1 -======= ->>>>>>> Stashed changes +average_and_export() \ No newline at end of file From 78a391dd050aa97d329717fd8d0b4f041b457df7 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:23:36 +0100 Subject: [PATCH 05/17] empty func --- RGB_traces.m | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 RGB_traces.m diff --git a/RGB_traces.m b/RGB_traces.m new file mode 100644 index 0000000..cc80136 --- /dev/null +++ b/RGB_traces.m @@ -0,0 +1,28 @@ +## Copyright (C) 2023 Loic +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} RGB_traces (@var{input1}, @var{input2}) +## +## @seealso{} +## @end deftypefn + +## Author: Loic +## Created: 2023-02-06 + +function retval = RGB_traces (image, iter) + I = imread (image); + +endfunction From f05cb7110d4f678d785987eb06a44b843b4f9a55 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:24:09 +0100 Subject: [PATCH 06/17] empty test file --- test_RGB_traces.m | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test_RGB_traces.m diff --git a/test_RGB_traces.m b/test_RGB_traces.m new file mode 100644 index 0000000..6868537 --- /dev/null +++ b/test_RGB_traces.m @@ -0,0 +1,5 @@ +clear all +close all +clc + +image = 'frames/frame0.jpg' \ No newline at end of file From 2cb4fb5e7079e462d6afe833ad628324bd9502c3 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:29:56 +0100 Subject: [PATCH 07/17] finalized changes to ouput ROI frames --- get_frames.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/get_frames.py b/get_frames.py index 25b04fb..4c5df3d 100644 --- a/get_frames.py +++ b/get_frames.py @@ -6,13 +6,13 @@ from PIL import Image # Opens the Video file video = 'my_face.mov' path_to_script = os.path.dirname(os.path.abspath(__file__)) -if os.path.exists(path_to_script + r"\frames_testing") == False: - os.mkdir(path_to_script + r"\frames_testing") +if os.path.exists(path_to_script + r"\frames") == False: + os.mkdir(path_to_script + r"\frames") def get_frames(vid): cap= cv2.VideoCapture(vid) i=0 - while i<10: + while cap.isOpened(): ret, img = cap.read() if ret == False: break @@ -45,18 +45,22 @@ def get_frames(vid): list_eh.append(eh) #rectangle on forhead - fx = min(list_ex) + list_ew[list_ex.index(min(list_ex))] - fy = max(list_ey) + 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) + 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) - x1 = x + fx - x2 = x + fx + 100 - y1 = y + fy - 150 - y2 = y + fy - 20 - imRGB = img[y1:y2, x1:x2] - - cv2.imwrite('frames_testing/frame'+str(i)+'.jpg',imRGB) i+=1 cap.release() From 540c79d5c69012e29c7a7e31d95ad92d0a133a7e Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 14:34:31 +0100 Subject: [PATCH 08/17] finalized output ROI frames --- get_frames.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/get_frames.py b/get_frames.py index 4c5df3d..152f622 100644 --- a/get_frames.py +++ b/get_frames.py @@ -56,13 +56,12 @@ def get_frames(vid): 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) - i+=1 - cap.release() cv2.destroyAllWindows() return From 3b7632c4511bbab2a28a069aac444bfe1fc03b6f Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:06:25 +0100 Subject: [PATCH 09/17] exporting a single line matrix of the RGB averages --- RGB_traces.m | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/RGB_traces.m b/RGB_traces.m index cc80136..6f7ff06 100644 --- a/RGB_traces.m +++ b/RGB_traces.m @@ -1,28 +1,27 @@ -## Copyright (C) 2023 Loic -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program. If not, see . +%%%%%%%%%%%%%%%%%%%%% +% 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 +%%%%%%%%%%%%%%%%%%%%% -## -*- texinfo -*- -## @deftypefn {} {@var{retval} =} RGB_traces (@var{input1}, @var{input2}) -## -## @seealso{} -## @end deftypefn - -## Author: Loic -## Created: 2023-02-06 - -function retval = RGB_traces (image, iter) +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 From 1b5d328bbdaf1c02dde5ca1a6142b04b73503e6f Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:07:26 +0100 Subject: [PATCH 10/17] tested, self explanitory --- matrix_avg.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 matrix_avg.m diff --git a/matrix_avg.m b/matrix_avg.m new file mode 100644 index 0000000..a4f8b32 --- /dev/null +++ b/matrix_avg.m @@ -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 From e847f2f25edead8084f2b6ca4d05f08992174668 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:08:23 +0100 Subject: [PATCH 11/17] tests the matrix avg func --- test_file.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test_file.m diff --git a/test_file.m b/test_file.m new file mode 100644 index 0000000..599247c --- /dev/null +++ b/test_file.m @@ -0,0 +1,16 @@ +clear all +close all +clc + +threshold = 1e-6; + +image = 'frames/frame0.jpg'; +%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 \ No newline at end of file From ad6a1e013f83b8f4ba4f4f4523bd77547ad6aef1 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:33:27 +0100 Subject: [PATCH 12/17] exports all of the avg RGB values for all frames of a video --- frames_RGBs.m | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 frames_RGBs.m diff --git a/frames_RGBs.m b/frames_RGBs.m new file mode 100644 index 0000000..101d242 --- /dev/null +++ b/frames_RGBs.m @@ -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_RBGs () + %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 From 8d2c639341d15890babe6f2d9df5e1a95439a907 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:35:57 +0100 Subject: [PATCH 13/17] prints amount of frames created --- get_frames.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/get_frames.py b/get_frames.py index 25b04fb..1158c42 100644 --- a/get_frames.py +++ b/get_frames.py @@ -61,5 +61,5 @@ def get_frames(vid): cap.release() cv2.destroyAllWindows() - return -get_frames(video) \ No newline at end of file + return i +print('number of frames extracted ' + get_frames(video)) \ No newline at end of file From 3eaeb633cd56b20ae2a0fe45d7061064f5a4aecb Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:36:16 +0100 Subject: [PATCH 14/17] same --- test_file.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_file.m b/test_file.m index 599247c..b120e6d 100644 --- a/test_file.m +++ b/test_file.m @@ -4,7 +4,8 @@ clc threshold = 1e-6; -image = 'frames/frame0.jpg'; +RGB_data = frames_RGBs (); + %TEST 1 %Average of all the items inside of a matrix A = [1, 2; 3, 4]; From af6fd07843a547dd07bf6825bcfbd1582073ed71 Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:37:18 +0100 Subject: [PATCH 15/17] not used anymore --- test_RGB_traces.m | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 test_RGB_traces.m diff --git a/test_RGB_traces.m b/test_RGB_traces.m deleted file mode 100644 index 6868537..0000000 --- a/test_RGB_traces.m +++ /dev/null @@ -1,5 +0,0 @@ -clear all -close all -clc - -image = 'frames/frame0.jpg' \ No newline at end of file From 698a3fa68ba19687ba1f5453ced5f86f4f172cfa Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:45:57 +0100 Subject: [PATCH 16/17] useless now --- RGB_channels.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/RGB_channels.py b/RGB_channels.py index efdfbc9..cfd0798 100644 --- a/RGB_channels.py +++ b/RGB_channels.py @@ -84,10 +84,8 @@ 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 - try: - out_colors = RGB_dataframe(read_img, i) - except: - out_colors = out_colors + + out_colors = RGB_dataframe(read_img, i) 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]) From b223ba0132235e39015a81223c80c7c2b367635c Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 15:46:49 +0100 Subject: [PATCH 17/17] fully exports all avg RGB datas of all frames, updated name infile --- frames_RGBs.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frames_RGBs.m b/frames_RGBs.m index 101d242..decc610 100644 --- a/frames_RGBs.m +++ b/frames_RGBs.m @@ -14,7 +14,7 @@ % date: 06/02/2023 %%%%%%%%%%%%%%%%%%%%% -function RGB_data = frames_RBGs () +function RGB_data = frames_RGBs () %frames_num = 918; j = 0; RGB_data = [0, 0, 0];