Created
April 14, 2023 06:24
-
-
Save lakpa-tamang9/8b208c6fd923ddedb4617fd24a88222c to your computer and use it in GitHub Desktop.
Resize images to uniform sizes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import os | |
root = "./photos/data" | |
files = os.listdir(root) | |
SIZE = (640, 480) | |
output_path = "./photos/resized_data" | |
if not os.path.exists(output_path): os.makedirs(output_path) | |
for file in files: | |
if file != '.DS_Store' and not file.endswith('.gif'): | |
filename = file.split(".")[0] | |
image = cv2.imread(os.path.join(root, file)) | |
# img = image.copy() | |
img = cv2.resize(image, SIZE) | |
cv2.imwrite(os.path.join(output_path, f"resized_{filename}.png"), img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment