Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenCV imread发布libpng错误:IEND:CRC错误,未加载图像_Python_Opencv_Libpng - Fatal编程技术网

Python OpenCV imread发布libpng错误:IEND:CRC错误,未加载图像

Python OpenCV imread发布libpng错误:IEND:CRC错误,未加载图像,python,opencv,libpng,Python,Opencv,Libpng,以下代码将此错误打印到终端,但不会停止执行:libpng错误:IEND:CRC错误 import numpy as np import cv2 import os # image is stored in the same location as the python file dir_path = os.path.dirname(os.path.realpath(__file__)) path = dir_path+'/test.png' # img always gets set as

以下代码将此错误打印到终端,但不会停止执行:
libpng错误:IEND:CRC错误

import numpy as np
import cv2
import os

# image is stored in the same location as the python file
dir_path = os.path.dirname(os.path.realpath(__file__))
path = dir_path+'/test.png'

# img always gets set as a NoneType
img = cv2.imread(path)
这是有问题的测试图像(是的,它是空白的):

一些Google Fu透露,不久前libpng的Anaconda包中有一个bug可能会导致这个问题,建议对其进行更新。我这样做毫无效果,因此,为了更好的衡量,我也回去确保我的机器上安装了libpng的最新版本。同样,没有变化

除此之外,我还尝试了代码的许多不同变体和操作条件,但仍然没有改变。具体而言,我尝试过:

  • 将图像更改为
    .jpg
    。错误不会弹出,显然是因为它不再使用libpng,但图像仍然以非类型返回
  • 传入额外标志,如
    cv2.IMREAD\u灰度
  • 在virtualenv中安装opencv(版本3.4.4.19和3.4.5.20)和numpy并运行它
  • 使用WSL和Raspberry Pi(3.5.3)在我的Windows笔记本电脑(Anaconda 3.6.5)上运行它

顺便说一句,我断断续续地使用OpenCV已经两年多了,几乎没有什么问题。我不能让这么简单/愚蠢的东西工作,这伤害了我的自尊心。我即将开始深入研究libpng文档,但我非常感谢您的任何评论或想法

如果在图像上运行
pngcheck
,它将告诉您
IEND
区块的校验和不正确:

pngcheck -v blank.png 
输出

File: blank.png (79830 bytes)
  chunk IHDR at offset 0x0000c, length 13
    2560 x 1600 image, 32-bit RGB+alpha, non-interlaced
  chunk IDAT at offset 0x00025, length 8192
    zlib: deflated, 32K window, fast compression
  chunk IDAT at offset 0x02031, length 8192
  chunk IDAT at offset 0x0403d, length 8192
  chunk IDAT at offset 0x06049, length 8192
  chunk IDAT at offset 0x08055, length 8192
  chunk IDAT at offset 0x0a061, length 8192
  chunk IDAT at offset 0x0c06d, length 8192
  chunk IDAT at offset 0x0e079, length 8192
  chunk IDAT at offset 0x10085, length 8192
  chunk IDAT at offset 0x12091, length 5937
  chunk IEND at offset 0x137ce, length 0
  CRC error in chunk IEND (computed ae426082, expected ae426080)
如果以十六进制转储文件:

xxd image.png > hex
然后在任何普通编辑器中编辑最后一个字节以使其正确,您可以使用以下命令重建文件:

xxd -r < hex > recovered.png
xxd-rrecovered.png

成功了!非常感谢!酷-问题(和答案)是免费的,所以如果你被卡住了,回来问吧。祝你的项目好运!