How to check a jpeg image whether corrupt?

2.1k Views Asked by At

Here, I use opencv imread read the all the image without any problem while it raise out Corrupt Data: xxx extraeous bytes before marker 0xd9 when training with neural networks. How could I get out these corrupt data(just select out, do not need repair or any other operations).

1

There are 1 best solutions below

3
On

Since you only want to filter out the corrupt files, you can use a try - except block:

for file in files:
    try:
        img = cv2.imread(file)
    except:
        pass