File size: 759 Bytes
e55378f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import cv2
import numpy as np

def load_images_from_folder(folder_path, img_size):
    emotions = sorted(os.listdir(folder_path))
    x_data = []
    y_data = []
    for idx, emotion in enumerate(emotions):
        emotion_folder = os.path.join(folder_path, emotion)
        for filename in os.listdir(emotion_folder):
            img_path = os.path.join(emotion_folder, filename)
            img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
            if img is not None:
                img = cv2.resize(img, img_size)
                x_data.append(img)
                y_data.append(idx)
    x_data = np.array(x_data)
    y_data = np.array(y_data)
    x_data = x_data.reshape(-1, img_size[0], img_size[1], 1)
    return x_data, y_data, emotions