Created
January 9, 2019 09:45
-
-
Save LouiS0616/915470970892de3df0f8228af2508e3f to your computer and use it in GitHub Desktop.
This file contains 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
from pathlib import Path | |
import cv2 | |
import numpy as np | |
from tqdm import tqdm | |
def main(filename): | |
# 画像を読み込む | |
img = cv2.imread(filename) | |
assert img is not None, f'Cannot open {filename}' | |
# フォルダの作成 | |
dst_filename_stem = Path(filename).stem | |
(Path('.') / dst_filename_stem).mkdir() | |
# 画像のリサイズ | |
height, width, _ = img.shape | |
img = cv2.resize(img, (width//4, height//4)) | |
# 画像の分割 & 保存 | |
strips = np.split(img, 12, axis=1) | |
for i in range(8): | |
work = strips[i:] + strips[:i] | |
dst = np.hstack(work) | |
cv2.imwrite(f'{dst_filename_stem}/{i:02d}.jpg', dst) | |
if __name__ == '__main__': | |
root = Path(r'...') | |
for img_file in tqdm(root.glob('*/*.jpg')): | |
img_file = str(img_file.resolve()) | |
main(img_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment