Created
September 19, 2020 15:06
-
-
Save aliyevorkhan/4aad4a29da463440b090e612783a3b58 to your computer and use it in GitHub Desktop.
This file contains 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 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