Skip to content
Snippets Groups Projects
Commit 820db5ec authored by Timothé Boulet's avatar Timothé Boulet :alien:
Browse files

add a loading file for a the DS fer2013

parent 176ba232
No related branches found
No related tags found
No related merge requests found
data
\ No newline at end of file
%% Cell type:code id: tags:
``` python
```
No preview for this file type
No preview for this file type
#This file load the dataset fer2013 as arrays.
import csv
import numpy as np
import cv2
import matplotlib.pyplot as plt
maxNbrImages = 484845
emotions = ["Angry", "Disgust", "Fear", "Happy", "Sad", "Suprise", "Neutral"]
def traitement(a,b,c): #For testing
arr = strToArray(b)
print(a)
plt.imshow(arr)
plt.show()
pass
def strToArray(string): #Fer2013 provides images as string so it needs to be transformed
A = []
lenght = len(string)
i=0
nbr = ""
while i<lenght:
car = string[i]
if car != " ":
nbr += car
else:
A.append(int(nbr))
nbr = ""
i+=1
A.append(int(nbr))
A = np.array(A)
A = np.reshape(A, (48, 48))
return A
#LOAD DATA AS ARRAY
X = []
Y = []
filename = "data/fer2013.csv"
with open(filename,'r',encoding='utf-8') as file:
csv_reader = csv.reader(file, delimiter=",")
next(csv_reader) #Passe la ligne de titre
i=0
for row in csv_reader:
i+=1
if i>maxNbrImages: break
emotionNbr, stringImage, typeImage = row
traitement(emotionNbr, stringImage, typeImage)
X.append(strToArray(stringImage))
Y.append(emotionNbr)
X = np.array(X)
Y = np.array(Y)
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import cv2 import cv2
import imageProcess as ip import imageProcess as ip
cap = cv2.VideoCapture(0) #0 means we capture the first camera, your webcam probably cap = cv2.VideoCapture(-1) #0 means we capture the first camera, your webcam probably
while cap.isOpened(): while cap.isOpened():
ret, frame = cap.read() #Read next video frame, stop if frame not well read ret, frame = cap.read() #Read next video frame, stop if frame not well read
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment