【问题标题】:OpenCv imdecode returns none for HEIC fileOpenCv imdecode 为 HEIC 文件返回无
【发布时间】:2021-10-20 15:19:48
【问题描述】:

我正在开发应用程序来调整图像大小。它适用于 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) 返回

我无法弄清楚为什么它不能使用 heic 文件。 有什么办法可以解决这个问题?

注意

我看过之前的类似问题,但没有一个对我有用。

【问题讨论】:

标签: python opencv heic


【解决方案1】:

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)

https://docs.opencv.org/4.5.4/d4/da8/group__imgcodecs.html

【讨论】:

  • 感谢您澄清我遗漏的事情。
  • 不客气!请标记为已解决。
猜你喜欢
  • 2023-04-06
  • 2018-07-19
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-04
相关资源
最近更新 更多