フォルダ内のJPG形式ファイルの解像度を一括して縮小する
code:python
import cv2, os
########
dirname = './shrinked/'
expansion = 'JPG'
shrink_ratio = 0.2 # 0 - 1
########
os.mkdir(dirname)
filenames = os.listdir()
images = []
for filename in filenames:
image = cv2.imread(filename)
width = round(image.shape1*shrink_ratio) height = round(image.shape0*shrink_ratio) dst = cv2.resize(image, dsize=(width, height))
cv2.imwrite(dirname + filename, dst)
縮小率はshrink_rationで設定
対象となる画像の拡張子はexpansionで指定