From f86a111048002fcc12eb17f8d7d555154dfb972a Mon Sep 17 00:00:00 2001 From: Loic Delattre Date: Mon, 6 Feb 2023 13:55:46 +0100 Subject: [PATCH] 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