png图片缺乏某些库,导致损坏,或者多余了一些数据会导致以下报错:

libpng warning: iCCP: known incorrect sRGB profile
libpng warning iccp extra compressed data

一些可能的解决方案:

已有方案

来自:https://blog.csdn.net/qq_37924224/article/details/119181028

libpng 1.6及以上版本增强了ICC profiles检查,所以发出警告。从 PNG 图像中删除 iCCP profiles。

可以先读取,再重新保存:

import cv2
from skimage import io
image = io.imread(path)
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)
cv2.imencode('.png',image)[1].tofile(path)

本文提供方案

观察到报错的图片根本无法打开,选择删除对应图片。

文件结构:

- all- train- folder1- img1.png- ....- imgn.png- foler2- ...- test- folder1- img1.png- ....- imgn.png- foler2- ...

实现功能:

重命名文件夹,重命名文件名称(ps: 原来是有中文的),使用convert命令转换png为jpg

import os
import cv2
import random dir_path = "all/train"def rename_folder():for idx, subdir in enumerate(os.listdir(dir_path)):new_folder = "%s_" % (str(random.randint(0,10000))) + str(idx)whole_subdir = os.path.join(dir_path, subdir)whole_newdir = os.path.join(dir_path, new_folder)# print(f"rename {whole_subdir} to {whole_newdir}")os.rename(whole_subdir, whole_newdir)def rename():# rename filesfor subdir in os.listdir(dir_path):whole_path = os.path.join(dir_path, subdir)for idx, img_name in enumerate(os.listdir(whole_path)):postfix = "png" if img_name.endswith("png") else "jpg"new_img_name = str(idx) + "." + postfixorg_path = os.path.join(whole_path, img_name)new_path = os.path.join(whole_path, new_img_name)#     print(f"rename {org_path} to {new_path}")os.rename(org_path, new_path)def convert_png2jpg():# convertfor subdir in os.listdir(dir_path):whole_path = os.path.join(dir_path, subdir)for img_name in os.listdir(whole_path):img_whole_path = os.path.join(whole_path, img_name)if img_name.endswith("png"):# print(img_whole_path)img = cv2.imread(img_whole_path)cv2.imwrite(img_whole_path, img)os.system("convert %s %s"% (img_whole_path, img_whole_path.replace("png", "jpg")))def main():# run with nohup# 1. rm nohup.out# 2. nohup python convert_png.pyrename_folder()rename()convert_png2jpg()if __name__ == "__main__":main()

这个时候有可能会出现报错:

这些无法convert的文件就是需要删除的对象,通过正则化方法匹配对应文件, 并删除。

import osdef main():rm_list = greps()rm(rm_list)def greps():import rerm_list = []file = "nohup.out"f = open(file, "r")for line in f.readlines():res = re.findall("`.+'", line)if res:rm_list.append(*res)return rm_listdef rm(rm_list):rm_list = [item.lstrip("`").rstrip("'") for item in rm_list]for item in rm_list:print("rm: ", item)os.system("rm %s" % item)if __name__ == "__main__":main()

libpng warning iCCP 错误处理方法相关推荐

  1. pygame: libpng warning: iCCP: known incorrect sRGB profile 报错

    这两天在写Python小飞机的时候,运行的时候很正常,但是当点击关闭程序的时候总会出现以下警告: 那就查查看吧. 问题原因: 原因就是这个因为libpng 1.6,太敏感了,1.6及以上版本增强了IC ...

  2. git报错 git libpng warning: iCCP以及fatal: Authentication failed for ‘https://git.weixin.qq.com‘

    git打卡,本来是老哥带着我做项目,纯git新手小白,以后出现问题自己解决了,顺便分享一下自己的经验,防止以后忘记,顺便给新人铺个路~ 我一开始在使用git clone的时候,一共出现了两个错误,到处 ...

  3. libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决

    libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决 目录 libpng warning: iCCP: known incorrect ...

  4. Python 的 libpng warning: iCCP: cHRM chunk does not match sRGB 报错处理

    libpng warning: iCCP: cHRM chunk does not match sRGB 报错处理 前言 处理方法 更新 前言 用python3.6.6 写了一段很简单的图像卷积处理代 ...

  5. 报错libpng warning: iCCP: cHRM chunk does not match sRGB

    Libpng Warring 无聊的时候想着用Python画个图玩玩吧,但出现了这个错误 libpng warning: iCCP: cHRM chunk does not match sRGB 当时 ...

  6. libpng warning: iCCP: known incorrect sRGB profile 报错

    libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决 目录 libpng warning: iCCP: known incorrect ...

  7. 已解决libpng warning: iccp: known incorrect sRGB profile

    已解决AttributeError: module 'pygame.time' has no attribute 'sleep' libpng warning: iccp: known incorre ...

  8. 解决9.png malformed以及libpng warning: iCCP

    2019独角兽企业重金招聘Python工程师标准>>> 错误一:AAPT err(Facade for ********): ERROR: 9-pathc image ******* ...

  9. Qt:解决使用png图片时,报错libpng warning: iCCP: known incorrect sRGB profile的问题

    在Qt中,如果使用某些格式png图片,可能会报警告libpng warning: iCCP: known incorrect sRGB profile,虽然没什么影响,但是看到这个警告非常的烦. 网上 ...

最新文章

  1. 随笔-20150513
  2. 通信电子线路期末复习第二章下
  3. GC垃圾回收的三色标记算法
  4. Elastic-Job中的ScriptJob
  5. 这些Android高级必会知识点你能答出来几个?含BATJM大厂
  6. oracle删除唯一索引sql语句_高级SQL之在选择语句中使用更新和删除
  7. Spring 实践 -拾遗
  8. Python爬虫十六式 - 第三式:Requests的用法
  9. %Error opening tftp://255.255.255.255/network config
  10. iOS 崩溃 问题 警告 错误2
  11. (最短路)17bupt新生赛——F. ch追妹
  12. springboot+shiro+jwt
  13. 深度学习:Image Object Detection方法
  14. 黑客之门的魅力:感染与加载
  15. 蒙特卡罗方法(Monte Carlo)
  16. 手写一个类似 element-ui 的可输入下拉选择
  17. 网工行业里的多面手,数据通信工程师2022年最新系统学习路线整理
  18. vue页面的定时刷新
  19. iOS资源帖-优秀博客、iOS开发技术文、学习网站
  20. 混合波束成形| 高速铁路通信系统的信道估计:Location-Aided mMIMO Channel Tracking and Hybrid Beamforming for High-Speed

热门文章

  1. Python中inplace参数
  2. 017 Vowels match
  3. netcat 使用方法
  4. 单片机复位和冷启动(掉电)的区别
  5. android壁纸应用,HPSTR - 可能是你见过最会玩的壁纸应用 - Android 应用 - 【最美应用】...
  6. 器件选型篇:二极管之肖特基选型
  7. 此地不留爷,自有留爷处
  8. 区块链与大数据结合分析
  9. 英语-非谓语动词作定语
  10. 有效沟通技巧慕课答案