unchanged from main
This commit is contained in:
parent
f95730b96d
commit
0bdea59850
|
|
@ -1,71 +1,24 @@
|
||||||
import cv2
|
import cv2
|
||||||
from PIL import Image
|
|
||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
import os.path
|
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():
|
def rep_files_init():
|
||||||
#create a directory to store the RGB datas ouptut
|
#create a directory to store the RGB datas ouptut
|
||||||
path_to_script = os.path.dirname(os.path.abspath(__file__))
|
path_to_script = os.path.dirname(os.path.abspath(__file__))
|
||||||
if os.path.exists(path_to_script + r"\RGB_database") == False:
|
if os.path.exists(path_to_script + r"\RGB database") == False:
|
||||||
os.mkdir(path_to_script + r"\RGB_database")
|
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
|
onlyfiles = next(os.walk(path_to_script + r"\frames"))[2] #get the amount of frames previously extracted
|
||||||
frames_num = len(onlyfiles)-1
|
frames_num = len(onlyfiles)-1
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|
||||||
onlyfiles = next(os.walk(path_to_script + r"\frames"))[2] #get the amount of frames previously extracted
|
return frames_num
|
||||||
frames_num = len(onlyfiles)-1
|
|
||||||
|
|
||||||
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):
|
def RGB_dataframe(img, itr):
|
||||||
<<<<<<< Updated upstream
|
|
||||||
=======
|
|
||||||
img = cv2.imread(image)
|
|
||||||
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
||||||
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
|
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
|
||||||
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||||
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
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
|
#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)
|
||||||
|
|
||||||
'''imS = cv2.resize(img, (960, 540))
|
imS = cv2.resize(img, (960, 540))
|
||||||
#cv2.imshow('img',imS)
|
#cv2.imshow('img',imS)
|
||||||
#cv2.waitKey(0)
|
#cv2.waitKey(0)
|
||||||
x1 = x + fx
|
x1 = x + fx
|
||||||
|
|
@ -108,35 +61,19 @@ def RGB_dataframe(img, itr):
|
||||||
#cv2.imshow('img',imRGB)
|
#cv2.imshow('img',imRGB)
|
||||||
#cv2.waitKey(0)
|
#cv2.waitKey(0)
|
||||||
|
|
||||||
|
R = []
|
||||||
|
G = []
|
||||||
|
B = []
|
||||||
size_list = list(imRGB.shape[:2])
|
size_list = list(imRGB.shape[:2])
|
||||||
pixel_values = []
|
pixel_values = []
|
||||||
for i in range(0, size_list[0]):
|
for i in range(0, size_list[0]):
|
||||||
for j in range(0, size_list[1]):
|
for j in range(0, size_list[1]):
|
||||||
k = imRGB[i,j]
|
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])
|
R.append(k[0])
|
||||||
G.append(k[1])
|
G.append(k[1])
|
||||||
B.append(k[2])'''
|
B.append(k[2])
|
||||||
|
|
||||||
return R, G, B
|
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():
|
def average_and_export():
|
||||||
i = 0
|
i = 0
|
||||||
count = 0.1
|
count = 0.1
|
||||||
|
|
@ -145,9 +82,10 @@ def average_and_export():
|
||||||
while i < frames_num:
|
while i < frames_num:
|
||||||
i += 1
|
i += 1
|
||||||
image = "frames/frame" + str(i) + ".jpg"
|
image = "frames/frame" + str(i) + ".jpg"
|
||||||
|
read_img = cv2.imread(image)
|
||||||
#Bug here inside of func with min funcs of empty data
|
#Bug here inside of func with min funcs of empty data
|
||||||
try:
|
try:
|
||||||
out_colors = RGB_dataframe(image, i)
|
out_colors = RGB_dataframe(read_img, i)
|
||||||
except:
|
except:
|
||||||
out_colors = out_colors
|
out_colors = out_colors
|
||||||
Ravg = sum(out_colors[0])/len(out_colors[0])
|
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:
|
with open('RGB database/RGB_data.csv', 'w', newline="") as f:
|
||||||
fields = ['R', 'G', 'B']
|
fields = ['R', 'G', 'B']
|
||||||
>>>>>>> Stashed changes
|
|
||||||
write = csv.writer(f)
|
write = csv.writer(f)
|
||||||
write.writerow(fields)
|
write.writerow(fields)
|
||||||
write.writerows(pixel_values)
|
write.writerows(pixel_values)
|
||||||
return
|
return
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
average_and_export()
|
||||||
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
|
|
||||||
Loading…
Reference in New Issue