Python 判断图像是否读取成功的方法
时间:2021-04-13 09:15:59|栏目:Python代码|点击: 次
大批量处理数据时,若因个别图像错误导致代码中断,从头再来比较浪费时间
对未成功读入的图像跳过(读图 import cv2)
for i in range(1,1000):
image = cv2.imdecode(np.fromfile('xxx.jpg', dtype=np.uint8), -1)
try:
image.shape
except:
print('fail to read xxx.jpg')
continue
......
若该图像可能不存在,即没有该图像的文件名,也可用try判断
try:
np.fromfile('xxx.jpg', dtype=np.uint8)
except:
continue
上一篇:Windows 7下Python Web环境搭建图文教程
栏 目:Python代码
本文标题:Python 判断图像是否读取成功的方法
本文地址:http://www.codeinn.net/misctech/100652.html






