I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2010-01-01 20:35:14-08 by janmartin
How to add the bearing to a jpg?
Hi, I have a lot of geotagged pictures and need to add the bearing to them. By bearing I mean the what direction the middle of the image "looks to". Images have been taken every 5 seconds "looking forward" from a moving car, so calculating the bearing from two images GPS coordinates will be accurate enough for my needs. Any suggestion how to do this? Thanks, Jan
Direct Responses: 12061 | Write a response
Posted on 2010-01-02 00:04:09-08 by exiftool in response to 12058
Re: How to add the bearing to a jpg?
Hi Jan,

GPS:ImageDirection and GPS:ImageDirectionRef could be used for this purpose. Unfortunately ExifTool will not do the calculation you need though (yet), so calculating the bearing would be up to you.

- Phil
Direct Responses: 12062 | Write a response
Posted on 2010-01-02 01:18:45-08 by janmartin in response to 12061
Re: How to add the bearing to a jpg?
Hi Phil, I have taken a picture every 5 seconds, and then geotagged them from a .gpx file. The .gpx file has an entry every 1 second. So is way more accurate. I think I know how to calculate and add GPS:ImageDirection and GPS:ImageDirectionRef from a series of images. But is there a way to use the more accurate gpx data instead? Jan
Direct Responses: 12065 | Write a response
Posted on 2010-01-02 12:11:34-08 by exiftool in response to 12062
Re: How to add the bearing to a jpg?
I think you may find that using the fixes separated by 5 seconds are better than 1 second unless you apply a smoothing filter to the GPS data. Due to the error in each reading, I would guess that the calculated bearing would be more accurate with the longer baseline.

- Phil
Direct Responses: 12070 | Write a response
Posted on 2010-01-02 15:14:55-08 by janmartin in response to 12065
Re: How to add the bearing to a jpg?
Hi Phil,

I wrote a perl script (don't laugh) to calculate the bearing, but always get this error when writing it to the image:
Tag 'ImageDirectionRef' does not exist
Tag 'ImageDirection' does not exist
Nothing to do.

Indeed, the tags do not exist beforehand, thats why i try to write them.

Please find the images i use for testing here:
http://www.diy-streetview.org/data/exiftool/bearing

#!/usr/bin/perl use Image::ExifTool; use Geo::Ellipsoid; # Example: # perl add_bearing.pl /home/me/images print "\nDirectory = $ARGV[0]"; my(@lines) = `exiftool -n -p \'\$FileName \$GPSLatitude \$GPSLongitude \$GPSAltitude \$GPSDateStamp + \$GPSTimeStamp \' -q -f $ARGV[0]`; @lines = sort(@lines); $size = @lines; for ($i=0; $i<$size-1; $i++) { ($FileName, $GPSLatitude, $GPSLongitude, $GPSAltitude, $GPSDateStamp, $GPSTimeStamp) = split(' ',$ +lines[$i]); ($FileNameA, $GPSLatitudeA, $GPSLongitudeA, $GPSAltitudeA, $GPSDateStampA, $GPSTimeStampA) = spli +t(' ',$lines[$i+1]); print"\n$FileName $FileNameA\n"; print"$GPSLatitude $GPSLatitudeA\n"; print"$GPSLongitude $GPSLongitudeA\n"; $geo = Geo::Ellipsoid->new(ellipsoid=>'WGS84', units=>'degrees'); my( $distance, $bearing ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeA, $GPSLongitudeA + ); $bearing = sprintf("%.2f", $bearing); print"bearing: $bearing\n"; system("exiftool -overwrite_original $ARGV[0]/$FileName \'-GPS:ImageDirectionRef=T\' \'-GPS:ImageD +irection=$bearing\'"); } # end for

Thanks,
Jan
Direct Responses: 12072 | Write a response
Posted on 2010-01-02 18:51:56-08 by exiftool in response to 12070
Re: How to add the bearing to a jpg?
Looks good.

Entirely my fault, sorry. I should have checked the tag name documentation instead of going by memory. The tags are actually named GPSImgDirectionRef and GPSImgDirection (no colon).

- Phil
Direct Responses: 12074 | Write a response
Posted on 2010-01-02 19:23:04-08 by janmartin in response to 12072
Re: How to add the bearing to a jpg?
So I changed the tags:

system("exiftool -overwrite_original $ARGV[0]/$FileName \'-GPSImageDirectionRef=T\' \'-GPSImageDire +ction=$bearing\'");

and got the same error:

49.9960369998889 49.995993
8.673561 8.673752
bearing: 109.66v Tag 'GPSImageDirectionRef' does not exist
Tag 'GPSImageDirection' does not exist
Nothing to do.

Can it be it is because the (emty) tags do not exist in the images?
Please have a look at the images them-selfs:
http://www.diy-streetview.org/data/exiftool/bearing

How to solve this?
Thanks,
Jan
Direct Responses: 12076 | Write a response
Posted on 2010-01-02 20:26:40-08 by exiftool in response to 12074
Re: How to add the bearing to a jpg?
Hi Jan,

There's no "a" or "e" in "GPSImgDirectionRef".

- Phil
Direct Responses: 12077 | Write a response
Posted on 2010-01-03 00:27:31-08 by janmartin in response to 12076
Re: How to add the bearing to a jpg?
Phil,
this is a bit embarrassing.

Anyway, here is the "working" script I came up with.
For accuracy I calculate the bearing differently for the first, middle and last image of a series.
Do you think the formulas are right?

May I ask you to take part in the GPled DIY-streetview project of mine?
We could really need some help.
I am available at janmartin AT diy-streetview DOT org for further information.

Thanks,
Jan

#!/usr/bin/perl # use Image::ExifTool; use Geo::Ellipsoid; # streetview_add_bearing.pl # # version 0.1 of January 2nd 2010. # The most up-to-date version of the script is available from: # http://www.diy-streetview.org/forum/viewforum.php?f=21 # # Licence: GPL 3 or later # Copyright: Jan of www.DIY-streetview.org # # What this is for: # This script is to calculate and add the bearing to individual streetviews of a series of streetvi +ews. # Streetviews typically are taken every 5 seconds from a moving car or bicycle etc. # # Assumtions: # This scipt assumes the middle of the streetview image points straight forward. (All streetviews I + know of do.) # # Usage: # Backup your original images! # Only ever work with copies! # # Run this file on a directory with GEOTAGGED panoramas (or simply photos) to add GPSImgDirectionRe +f and GPSImgDirection to the EXIF info. # # Example for Linux: # perl streetview_add_bearing.pl /home/me/streetviews # # This script has been tested on Ubuntu 9.10 Karmic Koala. print "\nDirectory = $ARGV[0]"; my(@lines) = `exiftool -n -p \'\$FileName \$GPSLatitude \$GPSLongitude \$GPSAltitude \$GPSDateStamp + \$GPSTimeStamp \' -q -f $ARGV[0]`; @lines = sort(@lines); $size = @lines; for ($i=0; $i<$size; $i++) { ($FileName, $GPSLatitude, $GPSLongitude, $GPSAltitude, $GPSDateStamp, $GPSTimeStamp) = split(' ',$ +lines[$i]); $geo = Geo::Ellipsoid->new(ellipsoid=>'WGS84', units=>'degrees'); if ($i == 0) { # first streetview F = Following ($FileNameF, $GPSLatitudeF, $GPSLongitudeF, $GPSAltitudeF, $GPSDateStampF, $GPSTimeStampF) = sp +lit(' ',$lines[$i+1]); my( $distanceF, $bearingF ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeF, $GPSLongitud +eF ); print"\nFirst:\n"; print"$FileName $FileNameF\n"; print"$GPSLatitude $GPSLatitudeF\n"; print"$GPSLongitude $GPSLongitudeF\n"; $bearingF = sprintf("%.2f", $bearingF); print"bearing: $bearingF\n"; system("exiftool -overwrite_original $ARGV[0]/$FileName \'-GPSImgDirectionRef=T\' \'-GPSImgDirec +tion=$bearingF\'"); } elsif($i<$size-1) { # middle streetviews M = Middle ($FileNameF, $GPSLatitudeF, $GPSLongitudeF, $GPSAltitudeF, $GPSDateStampF, $GPSTimeStampF) = sp +lit(' ',$lines[$i+1]); my( $distanceF, $bearingF ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeF, $GPSLongitud +eF ); ($FileNameB, $GPSLatitudeB, $GPSLongitudeB, $GPSAltitudeB, $GPSDateStampB, $GPSTimeStampB) = sp +lit(' ',$lines[$i-1]); my( $distanceB, $bearingB ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeB, $GPSLongitud +eB ); $bearingM=abs(($bearingB+$bearingF)/2); print"\nMiddle:\n"; print"$FileNameB $FileName $FileNameF\n"; print"$GPSLatitudeB $GPSLatitude $GPSLatitudeF\n"; print"$GPSLongitudeB $GPSLongitude $GPSLongitudeF\n"; $bearingM = sprintf("%.2f", $bearingM); print"bearing: $bearingM\n"; system("exiftool -overwrite_original $ARGV[0]/$FileName \'-GPSImgDirectionRef=T\' \'-GPSImgDirec +tion=$bearingM\'"); } elsif($i == $size-1) { # last streetview B = Befores ($FileNameB, $GPSLatitudeB, $GPSLongitudeB, $GPSAltitudeB, $GPSDateStampB, $GPSTimeStampB) = sp +lit(' ',$lines[$i-1]); my( $distanceB, $bearingB ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeB, $GPSLongitud +eB ); $bearingB=abs(180-$bearingB); print"\nLast:\n"; print"$FileNameB $FileName\n"; print"$GPSLatitudeB $GPSLatitude\n"; print"$GPSLongitudeB $GPSLongitude\n"; $bearingB = sprintf("%.2f", $bearingB); print"bearing: $bearingB\n"; system("exiftool -overwrite_original $ARGV[0]/$FileName \'-GPSImgDirectionRef=T\' \'-GPSImgDirec +tion=$bearingB\'"); } } # end for
Direct Responses: 12090 | Write a response
Posted on 2010-01-04 13:16:10-08 by exiftool in response to 12077
Re: How to add the bearing to a jpg?
Hi Jan,

This looks like an interesting and fun project and I wish I had time to be able to help you with it, but at the moment I have just about all I can handle between exiftool and my real work.

- Phil
Direct Responses: 12091 | Write a response
Posted on 2010-01-04 14:12:41-08 by janmartin in response to 12090
Re: How to add the bearing to a jpg?
Phil,

I am new to the Perl scene.
May I ask for a hint where to look for interested volunteers?

Thanks,
Jan
Direct Responses: 12092 | Write a response
Posted on 2010-01-04 14:43:37-08 by exiftool in response to 12091
Re: How to add the bearing to a jpg?
Hi Jan,

I think you'd be better off finding someone interested in streetview technology who knows a bit of Perl. But if you want Perl people, you should subscribe to the appropriate mailing list. See http://lists.perl.org/.

- Phil
Direct Responses: Write a response