1 year ago
#357391
Jose Vega
Open JPEG file with PIL and OpenCV fails
I have lots of images saved with no file extension.
I am trying to convert those images and do some work with PIL:
for img_path in list_imgs:
with Image.open(img_path) as img:
# more code
For some files this works ok but for others it shows PIL.UnidentifiedImageError
. I tried to handle the exception by opening the file with OpenCV:
img = cv2.imread(img_path)
But I get the following error:
[ WARN:0@2.312] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\grfmt_tiff.cpp (462) cv::TiffDecoder::readData OpenCV TIFF: TIFFRGBAImageOK: Sorry, requested compression method is not configured
If I manually changed the file extension to .jpg
for the specific file that files, I can open it using Windows Photos or any other app, even Microsoft Paint, so I know that the file is not damaged. However, both OpenCV and PIL have problems reading said file.
How can I open the image? Are there any other parameters that can be configured? Or can it be read directly into a NumPy array and then handled to PIL?
python
opencv
python-imaging-library
jpeg
0 Answers
Your Answer