问题描述
Corrupt JPEG data: 1 extraneous bytes before marker 0xdb
libpng warning: iCCP: known incorrect sRGB profile
Premature end of JPEG file
Premature end of JPEG file
Premature end of JPEG file
Premature end of JPEG file
使用opencv(python)读取图片时,报如上错误,据说是因为图片破损。try_except未能捕获该警告。该部分代码如下:
解决方案
使用PIL的读取函数。修改如下:
其中#1
处添加.convert("RGB")
,因为数据集含有RGBA(png)或者灰度图片,所有要进行类型转换。
如遇到如下警告,可使用warnings(warnings.filterwarnings(“ignore”))忽略。
PIL Palette images with Transparency expressed in bytes should be converted