Created
September 23, 2018 22:34
-
-
Save GeorgeSeif/b3f60265590c504eca6533d9fa319e0e 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
| import glob | |
| import os | |
| import cv2 | |
| import concurrent.futures | |
| def load_and_resize(image_filename): | |
| ### Read in the image data | |
| img = cv2.imread(image_filename) | |
| ### Resize the image | |
| img = cv2.resize(img, (600, 600)) | |
| ### Create a pool of processes. By default, one is created for each CPU in your machine. | |
| with concurrent.futures.ProcessPoolExecutor() as executor: | |
| ### Get a list of files to process | |
| image_files = glob.glob("*.jpg") | |
| ### Process the list of files, but split the work across the process pool to use all CPUs | |
| ### Loop through all jpg files in the current folder | |
| ### Resize each one to size 600x600 | |
| executor.map(load_and_resize, image_files) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment