カテゴリー
投資

resize

import logging
 import logging.config
 import yaml
 import cv2
 import os
 import imghdr
 import shutil
 with open('logger.yaml',mode= 'r') as f:
     config = yaml.safe_load(f.read())
     logging.config.dictConfig(config)
 logger = logging.getLogger('sampleLogger')
 logger.info('** START resize **')
 画像ファイルのlistを取得
 tmp_files = [x for x in os.listdir() if os.path.isfile(x)]
 files = [x for x in tmp_files if imghdr.what(x) != None]
 logger.info(f'tmp >> {files}')
 バックアップ
 if not os.path.exists('tmp'): os.makedirs('tmp')
 for bkfile in files: shutil.copy2(bkfile,'tmp')
 logger.info('バックアップ完了')
 リサイズ
 for filename in files:
     logger.info(f'{filename} resize 開始')
     img = cv2.imread(filename)
     height = img.shape[0]
     width = img.shape[1]
     width = int(width0.5)     height = int(height0.5)
     img2 = cv2.resize(img, (width, height))
     cv2.imwrite(filename, img2)
     logger.info(f'{filename} resize 完了')
 logger.info('** END resize **')

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です