提取照片坐标

# 拍照时需要手机打开GPS
import exifread


def get_picture_exif(picture_path):
    """ 提取图片元数据 """
    with open(picture_path, 'rb') as img_file:
        picture_info = exifread.process_file(img_file)
        if picture_info:
            try:
                latitude = picture_info['GPS GPSLatitude']  # 纬度数
                latituderef = picture_info['GPS GPSLatitudeRef']  # N,S 南北纬
                longitude = picture_info['GPS GPSLongitude']  # 经度数
                longituderef = picture_info['GPS GPSLongitudeRef']  # E,W 东西经
                date = picture_info['EXIF DateTimeOriginal']  # 拍摄时间
                image_software = picture_info['Image Software']

                # 做成度分时的状态
                def data_format(data):
                    data = str(data).replace('[', '').replace(']', '').split(',')
                    data_list = list()
                    data_list.append(data[0])
                    data_list.append('°')
                    data_list.append(data[1])
                    data_list.append('′')
                    data_tmp = data[-1].split('/')
                    data_list.append(str(int(data_tmp[0]) / int(data_tmp[1])))
                    data_list.append('′′')
                    gps = ''.join(data_list)
                    return gps

                if latitude and longitude and date:
                    print(r'纬度:{}{}经度:{}{}拍摄时间:{}拍摄软件:{}'.format(latituderef,
                        data_format(latitude), longituderef, data_format(longitude), date, image_software))
            except KeyError:
                print(r"关键字可能不存在")
        else:
            print('请检查提取的图片是否为原图,若为原图,则说明无相关元数据!')


if __name__ == '__main__':
    get_picture_exif(r'C:\Users\csi\Videos\1.jpg')

你可能感兴趣的:(提取照片坐标)