-
Notifications
You must be signed in to change notification settings - Fork 0
/
resizeImages.py
26 lines (23 loc) · 1.03 KB
/
resizeImages.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
import cv2
import os
import numpy as np
# This module resizes image from a given directory to 100*100 pixels and writes all images to given directory
count = 0
for path, subdirnames, filenames in os.walk("trainingImages"):
for filename in filenames:
if filename.startswith("."):
print("Skipping File:", filename) # Skipping files that startwith .
continue
img_path = os.path.join(path, filename) # fetching image path
print("img_path", img_path)
id = os.path.basename(path) # fetching subdirectory names
img = cv2.imread(img_path)
if img is None:
print("Image not loaded properly")
continue
resized_image = cv2.resize(img, (100, 100))
new_path = "resizedTrainingImages" + "/" + str(id)
# write all images to resizedTrainingImages/id directory
print("desired path is", os.path.join(new_path, "frame%d.jpg" % count))
cv2.imwrite(os.path.join(new_path, "frame%d.jpg" % count), resized_image)
count += 1