欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何利用python讀取圖片屬性信息

 更新時(shí)間:2022年03月09日 10:03:07   作者:alex1801  
這篇文章主要介紹了如何利用python讀取圖片屬性信息,文章圍繞python讀取信息相關(guān)資料展開(kāi)全文,具有一定的參考價(jià)值,需要的小伙伴可以參考一下

        從照片里面獲取GPS信息??山粨Q圖像文件常被簡(jiǎn)稱為EXIF(Exchangeable image file format),是專門為數(shù)碼相機(jī)的照片設(shè)定的,可以記錄數(shù)碼照片的屬性信息和拍攝數(shù)據(jù),EXIF信息不支持png,webp等圖片格式。

        Python中使用ExifRead包讀取圖片的屬性信息,安裝方式為:

pip install exifread

        使用exifread.process_file獲取圖像的信息:

img_path = r"bei_012744.jpg"
f = open(img_path, 'rb')
contents = exifread.process_file(f)
f.close()

        單步調(diào)試,contents內(nèi)容如下:

GPS坐標(biāo)轉(zhuǎn)換:

        通過(guò)exifread獲取的經(jīng)緯度信息格式通常是下面這樣的:緯度 [28, 56, 109097/5000] 經(jīng)度 [112, 38, 436353/10000],轉(zhuǎn)換公式如下:

度 = 度 + 分/60 + 秒/3600 
[28, 56, 109097/5000] = 28 + 56 / 60 + 109097/5000 / 3600 = 28.93939427777778

        因此坐標(biāo)轉(zhuǎn)換代碼如下:

def convert_gps(coord_arr):
? ? arr = str(coord_arr).replace('[', '').replace(']', '').split(', ')
? ? d = float(arr[0])
? ? m = float(arr[1])
? ? s = float(arr[2].split('/')[0]) / float(arr[2].split('/')[1])
? ? return float(d) + (float(m) / 60) + (float(s) / 3600)

        完整代碼:

import exifread
?
img_path = r"bei_012744.jpg"
f = open(img_path, 'rb')
contents = exifread.process_file(f)
f.close()
?
lon = contents['GPS GPSLongitude'].printable ?# 經(jīng)度
lon = convert_gps(lon)
lat = contents['GPS GPSLatitude'].printable ?# 緯度
lat = convert_gps(lat)
altitude = contents['GPS GPSAltitude'].printable ?# 相對(duì)高度
altitude = float(altitude.split('/')[0]) / float(altitude.split('/')[1])
?
print("GPSLongitude:", lon, "\nGPSLatitude:", lat, "\naltitude:", altitude)

        結(jié)果:

GPSLongitude: 112.64545425 
GPSLatitude: 28.93939427777778 
altitude: 58.009
 

 到此這篇關(guān)于如何利用python讀取圖片屬性信息的文章就介紹到這了,更多相關(guān)python讀取圖片屬性信息內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論