问题描述
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未能捕获该警告。该部分代码如下:

img = cv2.imread(img_path)
if img is None:
    img = np.zeros(shape=(224, 224, 3), dtype=np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)

解决方案
使用PIL的读取函数。修改如下:

img = None
try:
    img = Image.open(img_path).convert("RGB") #1
except:
    pass
if img is None:
    img = np.zeros(shape=(224, 224, 3), dtype=np.uint8)
    img = Image.fromarray(img)

其中#1处添加.convert("RGB"),因为数据集含有RGBA(png)或者灰度图片,所有要进行类型转换。

如遇到如下警告,可使用warnings(warnings.filterwarnings(“ignore”))忽略。

PIL Palette images with Transparency expressed in bytes should be converted
————————————————
版权声明:本文为CSDN博主「lsh呵呵」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/nima1994/article/details/102560730

ERROR | Corrupt JPEG data: 111 extraneous bytes before marker 0xd9...相关推荐

  1. imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be

    imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be ...

  2. Corrupt JPEG data: 2 extraneous bytes before marker 0x

    参考:http://www.voidcn.com/article/p-dusgpwtd-bpv.html cv2.imread(absolute_path) 有时会报错: Corrupt JPEG d ...

  3. 【Qt】QPixmap加载图片报错:Corrupt JPEG data: premature end of data segment Didn‘t expect more than one scan

    1.问题描述 在使用QPixmap加载图片时失败,错误信息如下 Corrupt JPEG data: premature end of data segment Didn't expect more ...

  4. Corrupt JPEG data: premature end of data segment

    在跑 LSTR 的效果时 , 用 tusimple数据集(1280720)正常,换成自集的数据集(12801080),出现 Corrupt JPEG data: premature end of da ...

  5. UserWarning: Possibly corrupt EXIF data.

    文章目录 前言 一.Exif是什么? 二.出现问题警告 三.问题分析 四.解决方法 前言 既然看到了这篇博客,那说明你用的数据集出毛病了,让我猜一猜,用的肯定是SUN397场景数据集吧?什么?不是?那 ...

  6. 成功解决Python中导出图片出现错误SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position

    成功解决Python中导出图片出现错误SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position ...

  7. Python读取文件时,出现SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3

    简短代码如下: import pandas as pd url = 'C:\Users\lic\Desktop\data\mp\1.csv' df = pd.read_csv(url) print(d ...

  8. FlowableException: Error initialising dmn data model报错问题

    flowable war包启动失败,报错Caused by: org.flowable.common.engine.api.FlowableException: Error initialising ...

  9. Php Fatal error: Allowed memory size of 33554432 bytes exhausted 的解决办法

    Php Fatal error: Allowed memory size of 33554432 bytes exhausted 的解决办法 在 php.ini 配置文档里面,默认的memory_li ...

  10. SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in positio n 131-135: truncate

    python报错 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio n 131-135: ...

最新文章

  1. 一张膜能把电信运营商挡在手机支付门外吗?
  2. [置顶]       Jquery为单选框checkbox绑定单击事件
  3. elementui 弹窗 显示详细信息_ElementUI中el-table双击单元格事件并获取指定列的值和弹窗显示详细信息...
  4. 【文末有奖】华为云“网红”语言Python课程来啦!
  5. java重div获取下拉框值_获取下拉框的value和值
  6. Spring Cloud Hystrix 进行服务熔断设置时,报错找不到对应的服务熔断方法
  7. Akka边学边写(3)-- ByteString介绍
  8. Dart入门—控制流程与其他
  9. Ajax异步请求PHP服务器,无阻塞响应的解决方案
  10. 基于Python的飞机大战游戏系统设计与实现
  11. 十进制和二进制相互转换
  12. oracle odi 资料档案库访问期间出现未分类的异常错误,ODI11g问题汇总
  13. Linux系统中VCS、Dve Verdi的使用
  14. Docker架构简介 命令详解
  15. 使用tensorboard出现:“couldn‘t build proto file into descriptor pool!”的解决方法
  16. jquery 垂直无限轮播
  17. calendar控件使用 extjs_ExtJs定制日历控件——自动加载更新(日历控件显示)
  18. 用python做flash动画_将Flash应用于Python项目
  19. 【项目分享】无线充电项目!!!
  20. bat脚本-指定程序列表选择运行

热门文章

  1. 初学RabbitMQ(三),了解回调函数,并手动确认消息进行消费
  2. LG-P3939 数颜色
  3. 读《Python编程:从入门到实践》
  4. 电脑键盘equals在哪个位置_常用标点符号和电脑键盘符号英语表示 -
  5. 51单片机按键:短按,长按,按下执行松开停止
  6. iOS开发之第三方登录微信-- 史上最全最新第三方登录微信方式实现
  7. Volatility FAQ
  8. 生物信息学基础知识Day4
  9. 来 看 T r i e 吧
  10. odoo14 Botton按钮标签属性详解及按钮图标使用