我一直在遵循指南,这些指南展示了从图像中提取GPS数据的相同步骤。它们中的大多数使用以下字典定义。
[exif definition][1]
exif = {
PIL.ExifTags.TAGS[k]: v
for k, v in pil_img._getexif().items()
if k in PIL.ExifTags.TAGS
}
但是,我一直得到AttributeError:_getexif和我不知道如何解决这个问题。我对蟒蛇很陌生。我已经确保我使用的图像有GPS信息,但我仍然不能访问任何元数据。下面是到目前为止的完整代码:注意,我正在使用cv2实践转换,因为这将适用于我的项目全码
from PIL import Image
import PIL
import cv2
import numpy as np
from PIL.ExifTags import TAGS
img = cv2.imread("keyboard.png")
convert = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
pil_img = Image.fromarray(convert)
exif = {
PIL.ExifTags.TAGS[k]: v
for k, v in pil_img._getexif().items()
if k in PIL.ExifTags.TAGS
}
此外,如果我试图像在教程中看到的那样调用exif,我会得到以下错误:exif不被识别
exif : The term 'exif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ exif
+ ~~~~
+ CategoryInfo : ObjectNotFound: (exif:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
发布于 2022-09-27 07:21:01
您的代码不可能以这种方式使用OpenCV。
当你这样做时:
img = cv2.imread("keyboard.png")
返回变量像素中的Numpy数组--仅此而已,没有EXIF,没有IPTC,没有ICC配置文件,绝对没有元数据。OpenCV只对计算机视觉感兴趣,而不是对图像进行编目、索引、排序、根据图像的拍摄地点、时间、对象或内容进行管理。
您可以使用PIL读取元数据,也可以使用exiftool
或其Python绑定--例如这里。
https://stackoverflow.com/questions/73850254
复制相似问题