python reads images with heic/heif suffix

1. Relevant background

A project requires reading .heic and .heif images using Python. But currently opencv does not support it. Shockingly, opencv, as the most professional and well-known open source image processing tool, does not support this image format that is widely used on iOS and Mac.
You can check for yourself about this codec algorithm. It is generally patented by Nokia. The compression effect is better than jpeg (50%). It is paid for by Apple (I don’t know if it is bought out).

2. Solution

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 pillow A plug-in package,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


3. Conclusion

  1. This is also the first time I know about this image format. Because I have been running Android for a long time, I have no access to images in this format. And images in this format will be automatically transcoded after being sent out by most software.
  2. The funniest thing is that OpenCV does not support it. This is not a niche format. OpenCV does not support it.

Guess you like

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