-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize.py
37 lines (30 loc) · 1.02 KB
/
resize.py
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
import cv2
import numpy as np
import os
# Folder name
path = "greyscale"
# Desired resolution
width = 64
height = 64
# Save location
save = "greyscalesave"
save_folder = os.path.join(os.getcwd(), save)
# student_id = "1141128570"
# Get address of current working directory
folder = os.path.join(os.getcwd(), path)
# Gets all contents of the address of folder
filenames = os.listdir(folder)
# Iterates through imagetest
for filename in filenames:
directories = os.path.join(folder, filename)
# directory = os.listdir(directories)
# Iterates through the subdirectories in imagetest
if filename == 'desktop.ini':
continue
letter = filename[9]
print("Currently at: ", filename)
# Reads the images in the subdirectories
array_img = cv2.imread(os.path.join(folder, filename))
# print(os.path.join(folder, filename))
resized_image = cv2.resize(array_img, (width, height))
cv2.imwrite(os.path.join(save_folder, filename[:3] + '_sized_%s_%s.jpg' % (letter, filename[12:21])), resized_image)