libpng error
现象:
现象1:可以正常获取类型
bool(imghdr.what(‘bad.png’)) #True
现象2: 不能读取,读取会报错,
img = cv2.imread(‘G:\tools\check\wrong_img\wrong_img\25.png’)
libpng error: bad adaptive filter value
img is None
True
现象3: 读取时不会立即报错,而是在程序执行完才报错
img = cv2.imread(“bad.png”)
img = cv2.imread(“30.png”)
print(“read end”)
if not img is None:
cv2.imshow(“img_roi”, img)
cv2.waitKey()
read end
libpng error: bad adaptive filter value
现象4: 换一种读入方式,会发现它只在解码时报错
r = open(file, ‘rb’).read() #可以读取
img_array = np.asarray(bytearray(r), dtype=np.uint8) # 可以转类型
img = cv2.imdecode(img_array, 1) # 解码出错 所以转换时要做解码判断
解决方案
使用 Image.open(path/to/image).tobytes() 触发错误并捕获它
I had some corrupted images, partially downloaded images to be precise, but i could not catch them using: imghdr.What(), Image.open().verify() or cv2.imread methods.
Only solution worked is this: Image.open(path/to/image).tobytes()
this code will throw error IOError if the image is corrupted.
hope it helps someone
try:
Image.open(path).tobytes()
except IOError:
print('detect error img %s' % path)
continue
上一篇: 线程 handler looper
下一篇: Handler倒计时跳转
推荐阅读
-
ERROR: Unrecognized command line argument: 'use'
-
jquery中ajax使用error调试错误的方法教程
-
Laravel 5.4中migrate报错: Specified key was too long error的解决
-
有关ajax的error与后台的异常问题解决
-
ERROR 1045 (28000): Access denied for user ''root''@''localhost'' (using passwor
-
MySQL 5.7.16 修改密码提示 ERROR 1054 (42S22): Unknown column ''password'' in ''field l
-
解决Zabbix网页端Get value error: cannot connect to [[192.168.238.139]:10050]: [113] N
-
mysql中异常错误ERROR:2002的解决方法
-
MYSQL error1044错误问题解决
-
camtasia studio8卸载失败提示Error1913怎么办?