forked from akshatat777/SiLT-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess_img.py
More file actions
57 lines (50 loc) · 1.52 KB
/
Copy pathpreprocess_img.py
File metadata and controls
57 lines (50 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from cv2 import data
import numpy as np
import cv2
import os
import random
from data_processing import resize
chars = ['A','B','C','D']
train_database = []
test_database = []
for c in chars:
for path in os.listdir(f'data/{c}'):
if path == '.DS_Store':
continue
for img_path in os.listdir(f'data/{c}/{path}'):
if img_path == '.DS_Store':
continue
image = cv2.imread(f'data/{c}/{path}/{img_path}')
# scales/pads the images so that they're all shape (100, 100, 3):
image = resize(image)
train_database.append([image,ord(path)-ord('a')])
for path in os.listdir(f'data/E'):
if path == '.DS_Store':
continue
for img_path in os.listdir(f'data/{c}/{path}'):
if img_path == '.DS_Store':
continue
image = cv2.imread(f'data/{c}/{path}/{img_path}')
# scales/pads the images so that they're all shape (100, 100, 3):
image = resize(image)
test_database.append([image,ord(path)-ord('a')])
random.shuffle(train_database)
random.shuffle(test_database)
imgs = []
labs = []
for img,label in train_database:
imgs.append(img)
labs.append(label)
t_imgs = []
t_labs = []
for img,label in test_database:
t_imgs.append(img)
t_labs.append(label)
imgs = np.array(imgs)
labels = np.array(labs)
t_imgs = np.array(t_imgs)
t_labels = np.array(t_labs)
np.save('data/images', imgs)
np.save('data/labels', labels)
np.save('data/test_images', t_imgs)
np.save('data/test_labels', t_labels)