I'm try to test images to see if any are corrupt. They all come back false, corrupted, but I know most or all are fine. What am I doing wrong?
Thanks.
import glob
from PIL import Image
import os
directory = r'C:\Users\Jim Schmitz\Documents\Pyro\dogs-vs-cats\train\dogs'
os.chdir(directory)
images=glob.glob("*.jpg")
def verify_image(img_file):
try:
img = Image.open(img_file)
except:
return False
return True
for image in images:
bool = verify_image('image')
You're passing the string
'image'as opposed to the filenameimage, your call should beverify_image(image). Also,boolis a built-in python object, try to refrain from using them as variable names.