gpt4 book ai didi

python - OpenCV imread 发布 libpng 错误 : IEND: CRC error and not loading images

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:42 25 4
gpt4 key购买 nike

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

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)

这是有问题的测试图像(是的,它是空白的):enter image description here

有Google-Fu透露前段时间libpng的Anaconda包存在bug导致该问题,建议更新。我这样做没有效果,因此,为了更好的衡量,我也回去确保我的机器上安装了最新版本的 libpng。同样,没有变化。

除此之外,我已经尝试了多种不同的代码变体和操作条件,但仍然没有任何变化。具体来说,我试过:

  • 将图像更改为 .jpg。错误没有弹出,显然是因为它不再使用 libpng,但图像仍然作为 NoneType 返回。
  • 传入额外的标志,如 cv2.IMREAD_GRAYSCALE
  • 在 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 block 的校验和不正确:

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

关于python - OpenCV imread 发布 libpng 错误 : IEND: CRC error and not loading images,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54096034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com