我正在编写一个基于python3 3的脚本,该脚本旨在基于提取的EXIF元数据将地理标记应用于.jpg图像的过程自动化。
PIL用于打开图像并读取EXIF元数据,pyexiv2用于将地理标记应用于.jpg图像。
应用地理标记的代码如下所示:
# Convert decimal coordinates to degrees, minutes, seconds
def to_degree(value, loc):
if value < 0:
loc_value = loc[0]
elif value > 0:
loc_value = loc[1]
else:
loc_value = ""
abs_value = abs(value)
deg = int(abs_value)
t1 = (abs_value-deg)*60
min = int(t1)
sec = round((t1 - min)* 60, 5)
return (deg, min, sec, loc_value)
# Apply geotags to photos based on converted latitude and longitude
def apply_geotags(photo, lat, lng):
# Convert coordinates into degrees, munutes and seconds
lat_deg = to_degree(lat, ["S", "N"])
lng_deg = to_degree(lng, ["W", "E"])
print(lat_deg)
print(lng_deg)
# Error here:
# AttributeError: module 'pyexiv2' has no attribute 'Rational'
exiv_lat = (pyexiv2.Rational(lat_deg[0]*60+lat_deg[1],60),pyexiv2.Rational(lat_deg[2]*100,6000), pyexiv2.Rational(0, 1))
exiv_lng = (pyexiv2.Rational(lng_deg[0]*60+lng_deg[1],60),pyexiv2.Rational(lng_deg[2]*100,6000), pyexiv2.Rational(0, 1))
print(exiv_lat)
print(exiv_lng)
# Error here:
# AttributeError: module 'pyexiv2' has no attribute 'ImageMetadata'
metadata = pyexiv2.ImageMetadata(photo)
metadata.read()
metadata["Exif.GPSInfo.GPSLatitude"] = exiv_lat
metadata["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
metadata["Exif.GPSInfo.GPSLongitude"] = exiv_lng
metadata["Exif.GPSInfo.GPSLongitudeRef"] = lng_deg[3]
metadata["Exif.Image.GPSTag"] = 654
metadata["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
metadata["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
metadata.write()我遇到了几个与pyexiv2相关的错误,包括
AttributeError: module 'pyexiv2' has no attribute 'Rational'和
AttributeError: module 'pyexiv2' has no attribute 'ImageMetadata'对于可以为.jpg映像应用/更新元数据的库,任何其他建议也将不胜感激。
https://stackoverflow.com/questions/57499928
复制相似问题