久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

Python怎么獲取照片的地理定位信息

178次閱讀
沒有評論

共計 1152 個字符,預計需要花費 3 分鐘才能閱讀完成。

要獲取照片的地理定位信息,可以使用 Python 的 PIL 庫(Python Imaging Library)或 ExifRead 庫。

首先,安裝 PIL 庫和 ExifRead 庫可以使用以下命令:

pip install pillow
pip install exifread

接下來,使用以下代碼可以獲取照片的地理定位信息:

使用 PIL 庫:

from PIL import Image
from PIL.ExifTags import TAGS

def get_geolocation(image_path):
    image = Image.open(image_path)
    exif_data = image._getexif()
    
    if exif_data is not None:
        for tag_id, value in exif_data.items():
            tag_name = TAGS.get(tag_id, tag_id)
            if tag_name == 'GPSInfo':
                return value

    return None

# 傳入照片路徑作為參數 
geolocation = get_geolocation('path/to/photo.jpg')
if geolocation is not None:
    print(geolocation)
else:
    print('No geolocation found.')

使用 ExifRead 庫:

import exifread

def get_geolocation(image_path):
    with open(image_path, 'rb') as image_file:
        tags = exifread.process_file(image_file)
        
        if 'GPS GPSLatitude' in tags and 'GPS GPSLongitude' in tags:
            latitude = tags['GPS GPSLatitude'].values
            longitude = tags['GPS GPSLongitude'].values
            return (latitude, longitude)

    return None

# 傳入照片路徑作為參數 
geolocation = get_geolocation('path/to/photo.jpg')
if geolocation is not None:
    print(geolocation)
else:
    print('No geolocation found.')

這些代碼將會輸出照片的地理定位信息,如果照片中不存在地理定位信息,則輸出’No geolocation found.’

丸趣 TV 網 – 提供最優質的資源集合!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2024-02-05發表,共計1152字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 泰兴市| 陆川县| 长乐市| 夹江县| 年辖:市辖区| 新和县| 来宾市| 高淳县| 巫山县| 松溪县| 伊金霍洛旗| 宜兴市| 孟村| 南阳市| 顺平县| 贺兰县| 黄石市| 博乐市| 永顺县| 赫章县| 辽宁省| 临湘市| 牟定县| 邢台县| 波密县| 娄烦县| 明水县| 临清市| 贵州省| 化州市| 常德市| 巴东县| 屏山县| 洛隆县| 冷水江市| 西平县| 大同县| 达孜县| 吉首市| 临汾市| 永登县|