Skip to content

Instantly share code, notes, and snippets.

@ryul99
Created April 9, 2020 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryul99/31e8b31366885e4e6781f6f91f34f88a to your computer and use it in GitHub Desktop.
Save ryul99/31e8b31366885e4e6781f6f91f34f88a to your computer and use it in GitHub Desktop.
import cv2
import glob
import os
import tqdm
from itertools import islice
from multiprocessing import Pool
from pathlib import Path
path = r'D:\Google Drive(SNU)\Study\Dataset\EDVR\Inference\dance_1080_120fs\dance_4k_60fps_downscaled\*.png'
img_size = [(1080, 2048,3)] # Width, Height
def split_image(_file):
if(os.path.isdir(_file)):
return
img = cv2.imread(_file, cv2.IMREAD_UNCHANGED)
try:
img.shape
except AttributeError:
print(_file)
if img.shape not in img_size:
raise ValueError("image shape (%s) is not in %s" % (img.shape, img_size))
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(split_image, files), total=len_total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment