-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Description
System information (version)
- OpenCV => opencv-python 4.6.0.66
- Operating System / Platform => Windows 10/11 64 bit
- Compiler => ❔
Detailed description
Python's OpenCV seems to be unable to read PNG images containing large tEXt chunks. Attempting to read such a PNG silently fails as cv2.imread returns None and a warning is logged to console:
libpng error: tEXt: chunk data is too large
In our specific example, the tEXt chunk is roughly 10 MB long.
This problem was reported to us in chaiNNer-org/chaiNNer#1007. The user was using a stable diffusion software (they did not mention which one) that would also take reference images (I presume). This software used a tEXt chunk in the output PNG to store the command line arguments used. Unfortunately, the reference image was passed in not as a file path, but as a data URI. So the command args stored as a tEXt chunk contains a roughly 10 MB data URI of a PNG image.
While I recognize that 10 MB tEXt chunks are quite large (maybe even unreasonably so), I do not think that this should cause OpenCV to not read the image. Most software seems to be able to read the attached PNG just fine (e.g. Windows explorer, Paint.Net, Windows Photos, Google Chrome, Firefox, MS Paint), so I think that OpenCV ought to be able to do the same.
Steps to reproduce
Download example.png: example.zip
Run the following code:
# repro.py
import cv2
path = r"path/to/example.png"
img = cv2.imread(path)
print("failed" if img is None else "success")Output on my machine:
PS C:\Users\micha\Git\chaiNNer> python .\repro.py
libpng error: tEXt: chunk data is too large
failed
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution - I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc