Skip to content

Instantly share code, notes, and snippets.

@aliyevorkhan
Created September 19, 2020 15:06
Show Gist options
  • Save aliyevorkhan/4aad4a29da463440b090e612783a3b58 to your computer and use it in GitHub Desktop.
Save aliyevorkhan/4aad4a29da463440b090e612783a3b58 to your computer and use it in GitHub Desktop.
import cv2
import glob, errno
# Replace mydir with the directory you want
mydir = 'Train1/'
#check if directory exist, if not create it
try:
os.makedirs(mydir)
except OSError as e:
if e.errno == errno.EEXIST:
raise
for fil in glob.glob("*.jpg"):
image = cv2.imread(fil)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # convert to greyscale
cv2.imwrite(os.path.join(mydir,fil),gray_image) # write to location with same name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment