Created
April 9, 2020 05:59
-
-
Save ryul99/cc065b8b950bc0b82d94f32e31a329dd 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
import cv2 | |
import glob | |
import os | |
import tqdm | |
from itertools import islice | |
from multiprocessing import Pool | |
from pathlib import Path | |
path = r'./**/*.png' | |
resize_factor = (0.5, 0.5) # Width, Height | |
def resize_image(_file): | |
img = cv2.imread(_file, cv2.IMREAD_UNCHANGED) | |
resized_img = cv2.resize(img, None, fx=resize_factor[0], fy=resize_factor[1]) | |
save_path = os.path.join('../resized_image', _file) | |
Path(os.path.dirname(save_path)).mkdir(parents=True, exist_ok=True) | |
cv2.imwrite(save_path, resized_img) | |
if __name__ == '__main__': | |
num_process = 16 | |
files = glob.glob(path, recursive=True) | |
len_total = len(files) | |
# iter_files = iter(files) | |
# files = [list(islice(iter_files, e)) for e in [len(files) // num_process] * (num_process + 1)] | |
with Pool(processes=num_process) as p: | |
r = list(tqdm.tqdm(p.imap(resize_image, files), total=len_total)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment