libpng warning iCCP 错误处理方法
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 错误处理方法相关推荐
- pygame: libpng warning: iCCP: known incorrect sRGB profile 报错
这两天在写Python小飞机的时候,运行的时候很正常,但是当点击关闭程序的时候总会出现以下警告: 那就查查看吧. 问题原因: 原因就是这个因为libpng 1.6,太敏感了,1.6及以上版本增强了IC ...
- git报错 git libpng warning: iCCP以及fatal: Authentication failed for ‘https://git.weixin.qq.com‘
git打卡,本来是老哥带着我做项目,纯git新手小白,以后出现问题自己解决了,顺便分享一下自己的经验,防止以后忘记,顺便给新人铺个路~ 我一开始在使用git clone的时候,一共出现了两个错误,到处 ...
- libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决
libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决 目录 libpng warning: iCCP: known incorrect ...
- Python 的 libpng warning: iCCP: cHRM chunk does not match sRGB 报错处理
libpng warning: iCCP: cHRM chunk does not match sRGB 报错处理 前言 处理方法 更新 前言 用python3.6.6 写了一段很简单的图像卷积处理代 ...
- 报错libpng warning: iCCP: cHRM chunk does not match sRGB
Libpng Warring 无聊的时候想着用Python画个图玩玩吧,但出现了这个错误 libpng warning: iCCP: cHRM chunk does not match sRGB 当时 ...
- libpng warning: iCCP: known incorrect sRGB profile 报错
libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决 目录 libpng warning: iCCP: known incorrect ...
- 已解决libpng warning: iccp: known incorrect sRGB profile
已解决AttributeError: module 'pygame.time' has no attribute 'sleep' libpng warning: iccp: known incorre ...
- 解决9.png malformed以及libpng warning: iCCP
2019独角兽企业重金招聘Python工程师标准>>> 错误一:AAPT err(Facade for ********): ERROR: 9-pathc image ******* ...
- Qt:解决使用png图片时,报错libpng warning: iCCP: known incorrect sRGB profile的问题
在Qt中,如果使用某些格式png图片,可能会报警告libpng warning: iCCP: known incorrect sRGB profile,虽然没什么影响,但是看到这个警告非常的烦. 网上 ...
最新文章
- 随笔-20150513
- 通信电子线路期末复习第二章下
- GC垃圾回收的三色标记算法
- Elastic-Job中的ScriptJob
- 这些Android高级必会知识点你能答出来几个?含BATJM大厂
- oracle删除唯一索引sql语句_高级SQL之在选择语句中使用更新和删除
- Spring 实践 -拾遗
- Python爬虫十六式 - 第三式:Requests的用法
- %Error opening tftp://255.255.255.255/network config
- iOS 崩溃 问题 警告 错误2
- (最短路)17bupt新生赛——F. ch追妹
- springboot+shiro+jwt
- 深度学习:Image Object Detection方法
- 黑客之门的魅力:感染与加载
- 蒙特卡罗方法(Monte Carlo)
- 手写一个类似 element-ui 的可输入下拉选择
- 网工行业里的多面手,数据通信工程师2022年最新系统学习路线整理
- vue页面的定时刷新
- iOS资源帖-优秀博客、iOS开发技术文、学习网站
- 混合波束成形| 高速铁路通信系统的信道估计:Location-Aided mMIMO Channel Tracking and Hybrid Beamforming for High-Speed