Dbarn
Posts: 5
Joined: Tue Apr 15, 2014 2:53 am

Add GPS Exif data in realtime

Tue Mar 03, 2015 9:05 pm

Hello,
I'm looking for a way to add exif location data to raspistill pictures in realtime. The end goal is to have accurate exif tags on raspistill images with Date, Time, and GPS Location.
Currently I'm using exiftool to tag the images, but that requires an accurate timestamp on the files. The pi is usually not connected to the network and gets powered on/off frequently, so it's time is rarely correct.

I have a USB GPS dongle (BU-353) connected to generate the gps tracks. I found this in the raspistill docs:
--exif GPS.GPSLongitude=5/1,10/1,15/100
But how can I:
1. Get the correct data from the GPS device
2. convert it to a format raspistill recognizes

Would the python picamera library work better?

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Add GPS Exif data in realtime

Tue Mar 03, 2015 9:26 pm

Look at the NMEA data there should be a $GPRMC sentence in the output, that has your "recommended course" which is your current location if you're stationary. Since you have a GPS you can use that to get a pin-point accurate timestamp. That's in the $GPRMC sentence as well.

We discussed the EXIF stuff back in 2013 and it should still work. http://www.raspberrypi.org/forums/viewt ... 43&t=46053
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7916
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Add GPS Exif data in realtime

Tue Mar 03, 2015 9:34 pm

Raspistill takes the data exactly as the EXIF tag requires. In the case of GPS, they are all listed out on http://www.awaresystems.be/imaging/tiff ... d/gps.html

GPSLatitude and GPSLongitude take 3 rational values for degrees, minutes, and seconds, hence the three fractions separated by commas.
GPSLatitudeRef and GPSLongitudeRef ought to be used to indicate N/S and E/W rather than using negative numbers.

I see Dougie has given you some info on reading the data from your GPS receiver whilst I've been typing this, so I've no further comment there.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Dbarn
Posts: 5
Joined: Tue Apr 15, 2014 2:53 am

Re: Add GPS Exif data in realtime

Wed Mar 04, 2015 5:06 pm

Thanks for the pointers, I really appreciate it. I'll have to dig into this a little when I get some free time.

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Fri Jun 19, 2015 8:04 am

For anyone who is interested, I've modified raspistill to read directly from gpsd and write GPS info to EXIF for my own use. This give me real-time GPS EXIF when raspistill is in timelapsed mode. It may be of use to others.
I've hard coded a few things, cut lots of corners, so don't expect fully tested code.

Attached is the modified raspistill binary and patch.

Edited to remove outdated binary and patch. Patch currently available in the pull-request. Latest binary further down this thread.
Last edited by draco on Mon Jul 06, 2015 2:28 pm, edited 1 time in total.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7916
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Add GPS Exif data in realtime

Fri Jun 19, 2015 8:45 am

draco wrote:For anyone who is interested, I've modified raspistill to read directly from gpsd and write GPS info to EXIF for my own use. This give me real-time GPS EXIF when raspistill is in timelapsed mode. It may be of use to others.
I've hard coded a few things, cut lots of corners, so don't expect fully tested code.

Attached is the modified raspistill binary and patch.
As long as it hasn't got a huge number of dependencies, feel free to push it to github and create a pull request for it to be merged into the main raspistill. It'll get code reviewed before being merged, but it sounds like it may be of use to others.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Add GPS Exif data in realtime

Tue Jun 23, 2015 12:04 pm

draco wrote:For anyone who is interested, I've modified raspistill to read directly from gpsd and write GPS info to EXIF for my own use. This give me real-time GPS EXIF when raspistill is in timelapsed mode. It may be of use to others.
I've hard coded a few things, cut lots of corners, so don't expect fully tested code.

Attached is the modified raspistill binary and patch.
This looks like it could be really useful with the kite photography blog of a few days ago. I would be useful to post some instructions to go with it.
thanks.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Add GPS Exif data in realtime

Tue Jun 23, 2015 12:24 pm

I've commented on the github push. Unfortunately the addition of the gps.h header and library breaks the standard build as the gpsd stuff isn't installed by default. Could you modify the code to dynamically load the library IF ITS PRESENT, and use as appropriate?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Wed Jul 01, 2015 2:53 am

I've updated the pull-request with dynamic loading of libgps. I've also attached 2 binary files for anyone who is interested but doesn't want to go through the compilation process.

raspistill.gpsd is the version in the pull-request as of today. Enable it with "-gps" option. If enabled, it expects libgps.so.20 to be present.

raspistill.gpsd.timelapse_besteffort (which is not in the pull-request) is the same as raspistill.gpsd except with the addition of best effort timelapse mode. It turns off frame skipping when it's not able to keep up with the timelapse frame rate. In other words, it captures as quickly as possible but no faster than the specified timelapse interval. It's for my own use, but someone else might find it useful. Enable it with "-be" option.

Edited to remove binaries. To get the new binaries, please read the following post.
Last edited by draco on Mon Jul 06, 2015 2:26 pm, edited 1 time in total.

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Mon Jul 06, 2015 2:23 pm

I've increased the resolution of the GPS latlong information in the EXIF tags.
Attached are the updated binaries.
Cheers.
Attachments
raspistill.gpsd.timelapse_besteffort.tar.gz
raspistill binary with gpsd support and no skipping frames in timelapse mode.
(49.36 KiB) Downloaded 107 times
raspistill.gpsd.tar.gz
raspistill binary with gpsd support (dynamic loading of libgps).
(48.95 KiB) Downloaded 125 times

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Add GPS Exif data in realtime

Mon Jul 06, 2015 3:00 pm

draco wrote:I've increased the resolution of the GPS latlong information in the EXIF tags.
Attached are the updated binaries.
Cheers.
Hi,
I will give this a go once I have the opportunity. I used your previous version of raspistill.gpsd successfully over the weekend with a USB GPS dongle.
I am particularly pleased that it doesn't 'bomb out' if the dongle is not connected, or doesn't have GPS lock :)

Thanks,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Wed Jul 08, 2015 5:27 am

I am particularly pleased that it doesn't 'bomb out' if the dongle is not connected, or doesn't have GPS lock :)
I'm not sure which is the best strategy when receiver losses GPS lock. My previous version caches the GPS data, and uses the cached data when it losses GPS lock. This is problematic as some images may contain "stale" or inaccurate GPS data. I've removed the data caching and just omit GPS EXIF when it doesn't have a GPS lock. This way, any GPS data written to EXIF is guaranteed to be accurate.

Feedback?

Attached are the updated binaries.
Attachments
raspistill.gpsd.timelapse_besteffort.tar.gz
raspistill binary with gpsd support and no skipping frames in timelapse mode.
(49.19 KiB) Downloaded 96 times
raspistill.gpsd.tar.gz
raspistill binary with gpsd support (dynamic loading of libgps).
(48.83 KiB) Downloaded 96 times

User avatar
DougieLawson
Posts: 37111
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Add GPS Exif data in realtime

Wed Jul 08, 2015 11:00 am

draco wrote: I'm not sure which is the best strategy when receiver losses GPS lock. My previous version caches the GPS data, and uses the cached data when it losses GPS lock. This is problematic as some images may contain "stale" or inaccurate GPS data. I've removed the data caching and just omit GPS EXIF when it doesn't have a GPS lock. This way, any GPS data written to EXIF is guaranteed to be accurate.
How accurate do you need to be (bearing in mind how inaccurate hobbyist GPS receivers are anyway)? How far are you moving between taking shots (metres or kilometres)?

If it's less than 10 metres then caching isn't any worse than a current locked fix.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Wed Jul 08, 2015 1:21 pm

DougieLawson wrote: If it's less than 10 metres then caching isn't any worse than a current locked fix.
Only problem is, without GPS lock and without additional sensors onboard, there's no way to work out the distance traveled.

On second thought, without GPS lock, we could estimate our current latlong from our last known latlong, speed and track.

If caching is desirable, maybe a cache expiry of 5 seconds combined with position estimation is more appropriate?

I still think it's better to be honest about not having GPS data than to lie and provide inaccurate data.

Ray Ishido
Posts: 5
Joined: Mon Dec 07, 2015 11:25 pm

Re: Add GPS Exif data in realtime

Wed Dec 09, 2015 1:12 am

Hi!

I tried it with Jessis but it didn't work with current version of libgps (v21).
I tried to make a symbolic link to libgps.so but the result was a Segmentation fault

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Tue Jan 12, 2016 4:55 am

Ray Ishido wrote: I tried it with Jessis but it didn't work with current version of libgps (v21).
I tried to make a symbolic link to libgps.so but the result was a Segmentation fault
There's API changes going from libgps20 (Wheezy) to libgps21 (Jessie). I have attached a new version of raspistill that supports libgps21 only, but haven't tested it. Use at your own risk...
Attachments
raspistill.gpsd.jessie.tar.gz
Raspistill with libgps21 support.
(46.71 KiB) Downloaded 83 times

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Tue Feb 02, 2016 1:33 am

I've reworked the code a little. Now it starts a thread to read the GPS information and caches the GPS information for up to 5 seconds. If it loses GPS lock, the GPS cache will be cleared after 5 seconds.

Latest source available here: https://github.com/raspberrypi/userland/pull/286
Latest binary available here: https://github.com/raspberrypi/userland ... gps.tar.gz
Last edited by draco on Thu Feb 04, 2016 11:25 pm, edited 1 time in total.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Add GPS Exif data in realtime

Tue Feb 02, 2016 9:27 am

Can you run this through valgrind (I think it now works on ARM) to check for memory issues but more specifically threading issues? (valgrind --tool=drd). I'd be interested to see if there are any issues.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

draco
Posts: 22
Joined: Fri Aug 15, 2014 6:42 am
Location: Melbourne, Australia

Re: Add GPS Exif data in realtime

Thu Feb 04, 2016 11:42 pm

I can't get valgrind to run. Any volunteer wants to look into it?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7916
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Add GPS Exif data in realtime

Fri Feb 05, 2016 8:09 am

Patch looked ok for memory leaks, but needed a mutex for thread safety. I haven't checked if you'd updated for that. I've never run valgrind so can't help there.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Add GPS Exif data in realtime

Fri Feb 05, 2016 8:19 am

I heard that Valgrind was now working on the Pi, might need to download the latest version it f it is working. It's pretty simple to use,

valgrind --tool=helgrind nameofapp

Will tell you any data races or other thread related issues.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7916
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Add GPS Exif data in realtime

Fri Feb 05, 2016 9:03 am

jamesh wrote:Will tell you any data races or other thread related issues.
And you'll find all those of your creation?! ;)
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Add GPS Exif data in realtime

Fri Feb 05, 2016 11:44 am

6by9 wrote:
jamesh wrote:Will tell you any data races or other thread related issues.
And you'll find all those of your creation?! ;)
Yup. I really ought to try it, but too busy valgrinding in anger for work! Found a few issues, including one I cannot figure out - might be a false positive deep in a C++ shared_ptr.

I did spend a month at Brcm running the ISP (compiled for PC) under Valgrind - the number of problems found was significant! Lots of races conditions, unprotected data, using uninitialized data etc. Fixed them all up, but not sure those changes ever made it to the Raspberry tree though.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7916
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Add GPS Exif data in realtime

Fri Feb 05, 2016 11:46 am

jamesh wrote:I did spend a month at Brcm running the ISP (compiled for PC) under Valgrind - the number of problems found was significant! Lots of races conditions, unprotected data, using uninitialized data etc. Fixed them all up, but not sure those changes ever made it to the Raspberry tree though.
Unlikely - the main camera algorithms were about a year out of date when we left. If they were all submitted then we can probably find them, but most won't apply cleanly due to the branches diverging.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25002
Joined: Sat Jul 30, 2011 7:41 pm

Re: Add GPS Exif data in realtime

Fri Feb 05, 2016 11:50 am

6by9 wrote:
jamesh wrote:I did spend a month at Brcm running the ISP (compiled for PC) under Valgrind - the number of problems found was significant! Lots of races conditions, unprotected data, using uninitialized data etc. Fixed them all up, but not sure those changes ever made it to the Raspberry tree though.
Unlikely - the main camera algorithms were about a year out of date when we left. If they were all submitted then we can probably find them, but most won't apply cleanly due to the branches diverging.
Pretty sure they were committed somewhere....and mostly they will be still relevant - a lot of the code where the problems were was pretty old. Also found a lot of problems simply by turning on all errors in the compiler.

Is it still possible to build the ISP for the PC from the tree you have access to?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

Return to “Camera board”