keith
keith

Reputation: 15

Try/Except Issue and Image Corruption

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')

Upvotes: -1

Views: 94

Answers (1)

Matt Prodani
Matt Prodani

Reputation: 109

You're passing the string 'image' as opposed to the filename image, your call should be verify_image(image). Also, bool is a built-in python object, try to refrain from using them as variable names.

Upvotes: 0

Related Questions