6

I'm working on a face detection project and want to know if opencv provides support for heic format in imread() and imwrite() methods? Can an image be read using cv2's imread() and written using cv2.imwrite() functions? (Language being used: Python3.6)

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • 1
    There is a [feature request](https://github.com/opencv/opencv/issues/14534). You may also check this [post](https://stackoverflow.com/questions/54395735/how-to-work-with-heic-image-file-types-in-python). – Rotem Mar 31 '20 at 13:34
  • i also want to know the result. – wolfog Apr 27 '20 at 08:50
  • @Rotem, I want to know specifically for OpenCV – opposite_orange Apr 28 '20 at 06:25
  • 1
    I did some research, and my conclusion is that OpenCV does **not** support .HEIC image format. – Rotem Apr 28 '20 at 09:38
  • It'd be great if you could provide some references. @Rotem – opposite_orange Apr 30 '20 at 10:59
  • A simple test is using [cv2.haveImageReader](https://docs.opencv.org/4.1.2/d4/da8/group__imgcodecs.html#ga0c3f60f18ed3a139e5a9926f9315e3bc) method (returns `False`). There is still a change that building OpenCV from sources, and including some extra packages makes it work. I followed the cmake options, and could not find any package that supports `.HEIC` format (except FFmpeg maybe. But you can't use `imread` with FFmpeg backend. Reading `.HEIC` as video frame is also not working). – Rotem Apr 30 '20 at 12:08
  • According to OpenCV documentation: List of image supported [formats](https://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56), and GDAL supported [formats](https://gdal.org/). "On MacOSX, there is also an option to use native MacOSX image readers", but I can't test it. – Rotem Apr 30 '20 at 13:53
  • So, images are read by cv2.imread but there're failures when I'm trying to write using cv2.imwrite. @Rotem – opposite_orange May 12 '20 at 06:23
  • In my machine, running Windows 10, I can't read or write `.HEIC` files. Are you using Mac? – Rotem May 12 '20 at 11:04
  • Yes. Also on further investigation, I found out that certain .HEIC images had mime type: JPEG (iPhone 11), but for iPhone 7 the mime type was: .heic @Rotem – opposite_orange May 14 '20 at 10:17
  • Note that you can use `pyvips`, or `wand`, or **ImageMagick** to either load .heic files directly for processing via **OpenCV**, or to convert them to TIFF or somesuch which **OpenCV** can then read itself... https://stackoverflow.com/a/71628557/2836621 – Mark Setchell Sep 03 '22 at 11:36

2 Answers2

4

According to the API docs of the latest available OpenCV (5.0-pre), HEIC is still not supported.

Update: As mentioned above, there's a feature request from May'19 in the OpenCV repo, which still has an "Open" status and unfortunately has a "Low" priority.

Slava Medvediev
  • 1,431
  • 19
  • 35
1

cv2's imread() 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)
  • 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)

doc link

Denis
  • 63
  • 6