Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python Picture processing Library exifread

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to use exifread in Python image processing library". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In fact, you can get not only GPS information, but also almost all the information of the picture. The function of exifread is actually instead of viewing picture properties! As shown below:

Here, use the camel photos taken in Sanya to do a demonstration to see if you can locate Sanya.

Note: if the picture is compressed, it will destroy the binary information inside, so you can't extract it.

The principle is: first read the picture in binary format, then extract the GPS information inside through the exifread library, and then print it in a specific format, and finally directly copy the longitude and latitude information inside, which can be located in the map that supports looking up the location through longitude and latitude.

The exifread library reads a binary example of a picture:

The specific code is as follows

Import exifreadimport re

# read pictures in binary format f = open ("luotuo.JPG", "rb") tags = exifread.process_file (f)

# GPS Information GPS = {}

# shooting time Data = ""

For tag,value in tags.items (): # get latitude information if re.match ('GPS GPSLatitude', tag): try: match_result=re.match ('\ [(\ w*), (\ w*), (\ w.*) / (\ w.*)\]' Str (value). Groups () GPS ['latitude'] = str (int (match_ result [0])) + "+ str (int (match_ result [1])) +" + str (int (match_result [2]) / int (match_ result [3]) except: GPS ['latitude'] = str (value) # get latitude information elif re.match ('GPS GPSLongitude' Tag): try: match_result=re.match ('\ [(\ w*), (\ w*), (\ w.*) / (\ w.*)\]' Str (value). Groups () GPS ['longitude'] = str (int (match_ result [0])) + "+ str (int (match_ result [1])) +" + str (int (match_result [2]) / int (match_ result [3]) except: GPS ['longitude'] = str (value) # get height elif re.match ('GPS GPSAltitude' Tag): GPS ['height'] = str (value) # get shooting time elif re.match ('Image DateTime', tag): Data = str (value)

# print information print ("Latitude:" + GPS ['Latitude'] + "," + GPS ['Longitude']) print ("shooting time:" + Data)

As shown in the figure, the read latitude and longitude information is displayed directly.

Expansion 1: in the later stage, we can directly convert latitude and longitude into specific locations through the API interface provided by Baidu. You can try it yourself!

Extension 2: of course, you can also find this information in the details of the properties of the right-click image.

If you want to keep it secret, you can delete the information by directly clicking to delete attributes and personal information.

This is the end of the content of "how to use exifread in Python Photo processing Library". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report