Archive for August, 2006

Gallery2 plugin - displaying googlemaps with GPS coordinates from EXIF

Thursday, August 31st, 2006

After resuming my geotaggin script (see this post), I decided to do something useful with it. We’re using gallery2 to store our photos and with a googlemap plugin, but found it useful only for displaying a single pointer per album (see here). For a more fine-grained selection we needed something else.

Therefore, I decided to write my own plugin (yeah, there are already two out there, why not write my own? ;-)) and also learn Gallery2 API. The idea is to display a google map at the bottom of each photo, showing exactly where the photo was taken. Yes, it photo-specific and there’s only one pointer on the map. I find it nonetheless very useful.

Here’s a sample output (you can also admire the beautiful scenery of Melchsee ;-)). The plugin adds a new “block” in the template (therefore can be configured using a standard block management tool in Gallery2).

The position of the current photo is always in the middle (although you can move the map around, change the map type, zoom in and out etc.). The changes you make are stored as session cookies, and preserved between consecutive photo loads. Also, the whole panel can be hidden to speed up load and only shown on demand (show map|hide map).

Any comments? suggestions? ideas?

The plugin is currently in alpha stage, I will release it in a week or two (I want to create a webpage for it as well). In the meantime, if you’re interested in trying it out, drop me a line ;-)

BTW: I also found out that when iPhoto edits a photo, it converts Exif from Intel to Motorola (little endian -> big endian). There was a bug in exifer used in gallery, which corrpted the tags. The patch is only two lines long and can be found here (I also emailed the author):

--- gps.inc.orig        2006-08-31 10:25:27.000000000 +0200
+++ gps.inc     2006-08-31 10:36:37.000000000 +0200
@@ -116,13 +116,24 @@
                        $minutes = GPSRational(substr($data,16,16),$intel);
                        $hour = GPSRational(substr($data,32,16),$intel);

  • /* now we need a hack, since the whole data has been flipped in :103
    • the order here is sec:min:hour. However, in the motorla mode the data
    • has not been flipped and the order is h:m:s. This breaks compatibility
    • with Motorola exif. (Tadek) */
  • if($intel==1) $data = $hour+$minutes/60+$seconds/3600;
  • else
  •                                 $data = $seconds+$minutes/60+$hour/3600;
            } else if($tag=="0007") { //Time
                    $seconds = GPSRational(substr($data,0,16),$intel);
                    $minutes = GPSRational(substr($data,16,16),$intel);
                    $hour = GPSRational(substr($data,32,16),$intel);
    
  •                 /* I guess the same HACK as above. Tadek */
    
  • if ($intel==1) $data = $hour.”:”.$minutes.”:”.$seconds;
  • else
  • $data = $seconds.”:”.$minutes.”:”.$hour; } else { if($bottom!=0) $data=$top/$bottom; else if($top==0) $data = 0;

GeoTagging in EXIF (resumed)

Thursday, August 31st, 2006

After almost a year after I had done some initial experiments with geotagging my images. I decided to pursue this idea further. I also realized that taking an approach “It’s simple let’s write in Perl” is good, but “Let’s see if somebody hasn’t done it yet” is even better ;-)

First, I recall I had some problems with reading GPS data and hacked gpstransfer to do this. In the meantime, I found out that pygarmin is a nice and working interface to Garmin GPSs, which works. More recently I discovered a much better and more versatile tool gpsbabel. Like the tower of Babel it really does speak all the languages (including plurality of GPS and very exotic formats (see here). The user interface is a bit weird and not all types of information (i.e. waypoints, tracks) are supported in all formats. Sadly, if the format is not supported, the program does transfer all the data (which takes a while) and prints nothing just to confuse you ;-)

After a bit of experimenting I discovered a magic formula:

gpsbabel -t -i garmin -f /dev/ttyS0 -o psitrex -F <track_file>

“psitrex” stands for KuDaTa PsiTrex format, however, as exotic as it sounds, it is just a comma separated format. I tried a couple of others (actually all of them in my version (1.2.7) and the only ones I found useful were:

  • psitrex -> an easy to parse CSV format
  • gpx -> produces results in XML
  • nmea -> looks ok, but does not show the start and end of each segment, which is useful for determining whether to interpolate data or not.

I also revisited my geotagging script. First, as Diego pointed out there’s a nice tool on Mac to do this: iPhototoGoogleEarth, which unfortunately doesn’t work on intel-Macs yet. For geotagging they use GPSPhotoLinker, which in turn uses gpsbabel. So at the end we use the same backend tool.

In the meantime I revisited my geotagging script and made it a bit more useful adding a bunch of options, debugging it, etc. Now that I actually use it on my photos, I had to make sure that it actually works ;-)

Here it is:

$ ./geotag.pl 
ERROR: Need track file to proceed - use -t <trackfile>
Usage:
  ./geotag.pl -t <track_file> [-b] [-f] [-s <seconds>] [-a <seconds>] [-n <seconds>] [-z <tz>] files_to_process...


  Where:
  -b -> keep backup,
  -f -> force, overwrites an existing EXIF tag (or removes it)
  -s <seconds> -> time shift (in case of time discrepancies)
  -a <seconds> -> approximate non-continuous segements in the tracklog (default 300s)
  -n <seconds> -> don't approximate but take the closest segment (default 10800s)
  -z <tz> -> use the follwoing timezone for your camera (default current timezone)

  <track_file> can be best created using gpsbabel (http://www.gpsbabel.org):
   (e.g. Serial Garmin GPS: gpsbabel -t -i garmin -f /dev/ttyS0 -o psitrex -F <track file>)    
   at ./geotag.pl line 288.

Now what do I do with the script? Well… I wrote a gallery2 plugin to display google maps. See this post.

Goodbye IBM, welcome Google

Wednesday, August 30th, 2006

After 3.5 years of work on my PhD and two months after submitting my thesis I left IBM Zurich Research Laboratory I left the Zurich Lab. Many thanks for the superb farewell lunch and all warm words!

Now, I am enojoying my week long vacation at home (or more precisely, trying to enojoy vacation while touching up on my MLJ submission. Still not done yet… grrr) and getting mentally ready for a new start (and my PhD defense in some time).

On Monday, I am starting a real job at Google in Zurich. I’m a bit anxious, but very much looking forward to it.

Wow. My blog is getting really personal this time… that’s second to last time, promise ;-)

Pusterla Elektronik

Tuesday, August 22nd, 2006

Ever wondered where to get some electronic components in Zurich and was unhappy with what quadruple “M” Migros offers in the hobby section? Or looking for a non-typical power supply for your favorite toy that just died? Or need some fancy cables? Or maybe just want to look at cool stuff? ;-)

I found a really nice electronic store in Zurich - Pusterla Elektronik to help you.