Skip to content

Instantly share code, notes, and snippets.

@vb100
Created July 11, 2017 20:00
Show Gist options
  • Save vb100/1f0992157c9def71964f2b9bfc72a297 to your computer and use it in GitHub Desktop.
Save vb100/1f0992157c9def71964f2b9bfc72a297 to your computer and use it in GitHub Desktop.
Batch resize all JPG images in project folder and save these images as new files in the same folder.
import cv2, glob #glob module - find path names of files
#1. Create a list of files that has extension of JPG
images=glob.glob("*.jpg")
for image in images:
#Read images path
img=cv2.imread(image,1)
#Create a variable where we will store resized image
re=cv2.resize(img,(int(img.shape[1]/6),int(img.shape[0]/6)))
#Check out that images has been resized
cv2.imshow("Checking",re)
#Each image should be visible for 0,5 sec on screen
cv2.waitKey(500)
cv2.destroyAllWindows()
#Write resized file to the project directory
cv2.imwrite("resized_"+image, re)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment