In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how to use python to read picture attribute information about the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
Get GPS information from the photo. Interchangeable image file is often referred to as EXIF (Exchangeable image file format), which is specially set for digital camera photos. It can record the attribute information and shooting data of digital photos. EXIF information does not support png,webp and other picture formats.
Use the ExifRead package in Python to read the attribute information of the image. The installation method is as follows:
Pip install exifread
Use exifread.process_file to get information about the image:
Img_path = r "bei_012744.jpg" f = open (img_path, 'rb') contents = exifread.process_file (f) f.close ()
For single-step debugging, the contents content is as follows:
GPS coordinate conversion:
The longitude and latitude information obtained through exifread is usually in the following format: latitude [28,56,109097amp 5000] longitude [112,38,436353max 10000], the conversion formula is as follows:
Degrees = degrees + minutes / 60 + seconds / 3600
[28,56,109097ax 5000] = 28 + 56 / 60 + 109097tick 5000 / 3600 = 28.939427777778
So the coordinate conversion code is as follows:
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)
Complete code:
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 # longitude lon = convert_gps (lon) lat = contents ['GPS GPSLatitude']. Printable # latitude lat = convert_gps (lat) altitude = contents [' GPS GPSAltitude']. Printable # relative height altitude = float (altitude.split ('/') [0]) / float (altitude.split ('/') [1]) print ("GPSLongitude:", lon "\ nGPSLatitude:", lat, "\ naltitude:", altitude)
Results:
GPSLongitude: 112.64545425
GPSLatitude: 28.93939427777778
Altitude: 58.009
The above is all the content of the article "how to use python to read picture attribute information". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.