我试图从一个大的图像数据集检测损坏的图像。我正在使用枕头包并验证()。 我只想检测损坏的图像或无法用图像查看器或浏览器打开的图像作为“坏苍蝇”,而我的所有图像总是检测为“坏的”
from os import listdir
from PIL import Image
for imageFolder in listdir('./batch1'):
try:
img = Image.open('./batch1'+imageFolder)
img.verify() # to veify if its an img
img.close() #to close img and free memory space
except (IOError, SyntaxError) as e:
print('Bad file:', imageFolder)
我做错什么了吗?在
有没有其他方法可以实现我的目标,即检测损坏的图像而不需要手动删除每个损坏的图像?在
您需要在路径后添加
/
。否则您的完整路径看起来像.'batch1your_img.png
还要确保您的
batch1
目录只包含图像,否则您将得到另一个错误。在相关问题 更多 >
编程相关推荐