GPS coordinate from jpeg file metadata

조회 수: 24(최근 30일)
Matteo Breda
Matteo Breda 2015년 5월 18일
댓글: Souka kiw 2018년 1월 4일
I'm working on a geo location progect and I need to plot some gps coordinate obtained from Jpeg pictures taken with a smartphone. Using info = imfinfo(filename) I get the information from the jpeg file but they are only ''visual'' information, so i would like to know if there's function to utilize the info i obtain from imfinfo to write a gps variable. To be clear:
info =
scalar structure containing the fields:
Filename = C:\Users\...\file.jpg
FileModDate = 28-Apr-2015 17:20:16
FileSize = 3129532
Format = JPEG
GPSInfo =
scalar structure containing the fields:
GPSLatitudeRef = N
GPSLongitudeRef = E
GPSAltitude = 44
GPSLatitude =
GPSLongitude =
imglatitude=*GPSLatitude obtanined from imfinfo*
I've got no clue about how to get this gps info out from the imfinfo function! Thanks in advance for your help
  댓글 수: 1
Souka kiw
Souka kiw 2018년 1월 4일
can you give me picture to test it ?

댓글을 달려면 로그인하십시오.

채택된 답변

Amy Haskins
Amy Haskins 2015년 5월 18일
The data returned from imfinfo is a structure and the fields can be accessed individually. If you have access to the Mapping Toolbox then with a little bit of effort you can use the wmmarker function display your image on a map.
Example: Use a sample image from the Image Processing Toolbox which contains geographic data.
handsInfo = imfinfo('hands1.jpg');
Display the GPS information
ans =
GPSLatitudeRef: 'N'
GPSLatitude: [42 17 57.0600]
GPSLongitudeRef: 'W'
GPSLongitude: [71 21 5.8200]
GPSAltitudeRef: 0
GPSAltitude: 69.7069
GPSTimeStamp: [16 48 35]
GPSImgDirectionRef: 'T'
GPSImgDirection: 291.9459
GPSDateStamp: '2014:03:11'
Note that the latitude and longitude are given in Degrees, Minutes, and Seconds (DMS). We will need to convert them to decimal degrees.
lat = dms2degrees(handsInfo.GPSInfo.GPSLatitude);
lon = dms2degrees(handsInfo.GPSInfo.GPSLongitude);
The GPSLatitudeRef and GPSLongitudeRef fields determine if the lat and lon should be positive or negative.
if strcmp(handsInfo.GPSInfo.GPSLatitudeRef,'S')
lat = -1 * lat;
if strcmp(handsInfo.GPSInfo.GPSLongitudeRef,'W')
lon = -1 * lon;
Display the photo on a webmap to put it in context. This particualar image is small, but for a larger image you might want to use imresize to create a smaller thumbnail.
wmmarker(lat, lon, 'OverlayName', 'Hands1', 'Description', ...
'Photo taken at The Mathworks, Inc', 'Icon', 'hands1.jpg')
  댓글 수: 3
Jesus Garcia
Jesus Garcia 2017년 10월 30일
Just put [] to group the 3 vectors and it will work:
lat = dms2degrees([handsInfo.GPSInfo.GPSLatitude]);
lon = dms2degrees([handsInfo.GPSInfo.GPSLongitude])

댓글을 달려면 로그인하십시오.

추가 답변(0개)


아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by