Doubt 1: For HEIC images, the return value provided by Magic is JPEG. Can someone help me with the explanation? Doubt 2: Why is cv2.imread reading the images when in the supported file formats .HEIC is not present? Also, if there's support for cv2.imread, why is there no support for cv2.imwrite?
import cv2
import os
from pathlib import Path
import magic
path_of_directory = str(Path(os.getcwd()).parent) + '/images'
images = os.listdir(path_of_directory)
for image in images:
try:
path = str(Path(os.getcwd()).parent) + '/images/' + image
write_path = str(Path(os.getcwd()).parent) + '/image_write/' + image
print("image is {}".format(image))
image_mat = cv2.imread(path)
print("shape: {}".format(image_mat.shape))
mime = magic.Magic(mime=True)
mime_type = mime.from_file(path)
print("mime_type: {}".format(mime_type))
cv2.imwrite(write_path, image_mat)
return_value = cv2.haveImageReader(path)
print("opencv will read the image: {}".format(return_value))
except Exception as e:
print("Exception occurred: {}".format(e))
