Last active
July 20, 2022 12:43
-
-
Save ThomasParistech/701bd0042f6602cbe0261865ffffd2b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # /usr/bin/python3 | |
| """Multiprocess folder of images""" | |
| import os | |
| from typing import List | |
| import cv2 | |
| import numpy as np | |
| from multi_process import KwargsType | |
| from multi_process import multiprocess | |
| from num_jobs import bytes_of_uint8_img | |
| def process_img(path: str, out_path: str, blur_radius: int, rotate: bool): | |
| img = cv2.imread(path) | |
| img = cv2.blur(img, (blur_radius, blur_radius)) | |
| if rotate: | |
| img = np.rot90(img) | |
| cv2.imwrite(out_path, img) | |
| if __name__ == "__main__": | |
| in_folder = "data/input" | |
| out_folder = "data/out" | |
| os.makedirs(out_folder, exist_ok=True) | |
| names = [f.name for f in os.scandir(in_folder)] | |
| list_kwargs: List[KwargsType] = [{"path": os.path.join(in_folder, name), | |
| "out_path": os.path.join(out_folder, name)} | |
| for name in names] | |
| shared_kwargs: KwargsType = {"blur_radius": 7, | |
| "rotate": True} | |
| first_img_path = os.path.join(in_folder, names[0]) | |
| n_bytes_per_process = bytes_of_uint8_img(first_img_path, colored=True) | |
| multiprocess(process_img, list_kwargs, shared_kwargs, n_bytes_per_process) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment