OpenCv imdecode returns none 用于 HEIC 文件
OpenCv imdecode returns none for HEIC file
我正在处理调整图像大小的应用程序。它可以很好地处理 jpg、png、jpeg 图像格式,但它不能像预期的那样处理 heic 文件。
错误:
OpenCV(4.4.0) /tmp/pip-req-build-vu_aq9yd/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
代码片段
npimg = np.frombuffer(stream.read(), np.uint8)
img = cv2.cvtColor(cv2.imdecode(npimg, cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)
h, w = cls.get_dims(img, dpi)
img = cv2.resize(img, (w, h), interpolation=cv2.INTER_AREA)
return Image.fromarray(img).convert("RGB")
我发现的是:
cv2.imdecode(npimg, cv2.IMREAD_COLOR)
returns none.
我不明白为什么它不能使用 heic 文件。
这个问题的解决方案是什么?
注:
我已经浏览过之前的类似问题,但是 none 对我有用。
OpenCV 不支持 heic 文件。来自 OpenCV 文档:
Currently, the following file formats are supported:
Windows bitmaps - *.bmp, *.dib (always supported)
JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section)
JPEG 2000 files - *.jp2 (see the Note section)
Portable Network Graphics - *.png (see the Note section)
WebP - *.webp (see the Note section)
Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)
PFM files - *.pfm (see the Note section)
Sun rasters - *.sr, *.ras (always supported)
TIFF files - *.tiff, *.tif (see the Note section)
OpenEXR Image files - *.exr (see the Note section)
Radiance HDR - *.hdr, *.pic (always supported)
Raster and Vector geospatial data supported by GDAL (see the Note section)
我正在处理调整图像大小的应用程序。它可以很好地处理 jpg、png、jpeg 图像格式,但它不能像预期的那样处理 heic 文件。
错误:
OpenCV(4.4.0) /tmp/pip-req-build-vu_aq9yd/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
代码片段
npimg = np.frombuffer(stream.read(), np.uint8)
img = cv2.cvtColor(cv2.imdecode(npimg, cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)
h, w = cls.get_dims(img, dpi)
img = cv2.resize(img, (w, h), interpolation=cv2.INTER_AREA)
return Image.fromarray(img).convert("RGB")
我发现的是:
cv2.imdecode(npimg, cv2.IMREAD_COLOR)
returns none.
我不明白为什么它不能使用 heic 文件。 这个问题的解决方案是什么?
注:
我已经浏览过之前的类似问题,但是 none 对我有用。
OpenCV 不支持 heic 文件。来自 OpenCV 文档:
Currently, the following file formats are supported:
Windows bitmaps - *.bmp, *.dib (always supported)
JPEG files - *.jpeg, *.jpg, *.jpe (see the Note section)
JPEG 2000 files - *.jp2 (see the Note section)
Portable Network Graphics - *.png (see the Note section)
WebP - *.webp (see the Note section)
Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)
PFM files - *.pfm (see the Note section)
Sun rasters - *.sr, *.ras (always supported)
TIFF files - *.tiff, *.tif (see the Note section)
OpenEXR Image files - *.exr (see the Note section)
Radiance HDR - *.hdr, *.pic (always supported)
Raster and Vector geospatial data supported by GDAL (see the Note section)