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')
except:
    continue
https://blog.csdn.net/ghy_111/article/details/80840433

猜你喜欢

转载自blog.csdn.net/hnshahao/article/details/81028677