【发布时间】:2018-04-01 22:38:57
【问题描述】:
我编写了一个 python 脚本来检测损坏的图像并计算它们, 我的脚本中的问题是它检测到所有图像并且没有检测到损坏的图像。如何解决这个问题。我参考了:
How to check if a file is a valid image file? 我的代码
我的代码
import os
from os import listdir
from PIL import Image
count=0
for filename in os.listdir('/Users/ajinkyabobade/Desktop/2'):
if filename.endswith('.JPG'):
try:
img=Image.open('/Users/ajinkyabobade/Desktop/2'+filename)
img.verify()
except(IOError,SyntaxError)as e:
print('Bad file : '+filename)
count=count+1
print(count)
【问题讨论】:
标签: python image jpeg python-imaging-library python-3.6