Skip to content

Instantly share code, notes, and snippets.

@lakpa-tamang9
Created April 14, 2023 06:24
Show Gist options
  • Save lakpa-tamang9/8b208c6fd923ddedb4617fd24a88222c to your computer and use it in GitHub Desktop.
Save lakpa-tamang9/8b208c6fd923ddedb4617fd24a88222c to your computer and use it in GitHub Desktop.
Resize images to uniform sizes.
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