HEIF image encoding standard - python reads HEIF images

1. Relevant background

Online paddle OCR error reporting, found that opencv read heic image error reporting, to learn about the heif encoding format

2. What is HEIF

The full name of HEIF: High Efficiency Image File Format . It is a container format used to store single images or image sequences. The HEIF standard includes a variety of media formats, such as audio, video, and time text. And it can store image sequences composed of images with different encoding methods.

For details, see https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format

In short, HEIF is a new container that can store various multimedia data.

3. Multiple variant suffixes of HEIF

There are many variant formats based on HEIF, such as the .heic image format taken by iPhone. In addition, there are also .avci, .avif and other formats

These different suffix names are just to describe the encoding method used by the image or image sequence.

  • . heic indicates that the codec used is a HEVC-related codec. If it is a single picture, it is the intra-frame coding algorithm of HEVC's I-frame. If it is an image sequence, it is the HEVC video coding algorithm.
  • . avci indicates that the encoding algorithm is AVC related
  • .avif indicates that the encoding algorithm is related to AV1

4. Why does opencv not support HEIF?

HEIF format support in OpenCV · Issue #14534 · opencv/opencv (github.com)

  • HEIF may not contain a picture, so it cannot be read directly with imread. Because the goal of imread is to read a picture
    Insert image description here

Appendix, solution for opencv being unable to read heif

https://stackoverflow.com/questions/54395735/how-to-work-with-heic-image-file-types-in-python

There are several solutions, but here is the simplest one

With the help of a plug-in package from pillow,pillow-heif

'''
需要安装pip3 install pillow-heif
'''

from PIL import Image
from pillow_heif import register_heif_opener

register_heif_opener()

image = Image.open('image.heic') # RGB, not BGR

Guess you like

Origin blog.csdn.net/qq_29007291/article/details/127576444