Author Topic: How to add the bearing to a jpg?  (Read 5162 times)

Archive

  • Newbie
  • *
  • Posts: 0
How to add the bearing to a jpg?
« on: May 12, 2010, 08:54:43 AM »
[Originally posted by janmartin on 2010-01-01 20:35:14-08]

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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #1 on: May 12, 2010, 08:54:43 AM »
[Originally posted by exiftool on 2010-01-02 00:04:09-08]

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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #2 on: May 12, 2010, 08:54:43 AM »
[Originally posted by janmartin on 2010-01-02 01:18:45-08]

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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #3 on: May 12, 2010, 08:54:43 AM »
[Originally posted by exiftool on 2010-01-02 12:11:34-08]

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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #4 on: May 12, 2010, 08:54:43 AM »
[Originally posted by janmartin on 2010-01-02 15:14:55-08]

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

Code:
#!/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) = split(' ',$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:ImageDirection=$bearing\'");
} # end for

Thanks,

Jan

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #5 on: May 12, 2010, 08:54:43 AM »
[Originally posted by exiftool on 2010-01-02 18:51:56-08]

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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #6 on: May 12, 2010, 08:54:43 AM »
[Originally posted by janmartin on 2010-01-02 19:23:04-08]

So I changed the tags:

Code:
system("exiftool -overwrite_original $ARGV[0]/$FileName \'-GPSImageDirectionRef=T\' \'-GPSImageDirection=$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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #7 on: May 12, 2010, 08:54:43 AM »
[Originally posted by exiftool on 2010-01-02 20:26:40-08]

Hi Jan,

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

- Phil

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #8 on: May 12, 2010, 08:54:43 AM »
[Originally posted by janmartin on 2010-01-03 00:27:31-08]

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

Code:
#!/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 streetviews.
# 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 GPSImgDirectionRef 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) = split(' ',$lines[$i+1]);
         my( $distanceF, $bearingF ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeF, $GPSLongitudeF );
         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\' \'-GPSImgDirection=$bearingF\'");
      }
      elsif($i<$size-1) { # middle streetviews M = Middle
         ($FileNameF, $GPSLatitudeF, $GPSLongitudeF, $GPSAltitudeF,  $GPSDateStampF, $GPSTimeStampF) = split(' ',$lines[$i+1]);
         my( $distanceF, $bearingF ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeF, $GPSLongitudeF );
         ($FileNameB, $GPSLatitudeB, $GPSLongitudeB, $GPSAltitudeB,  $GPSDateStampB, $GPSTimeStampB) = split(' ',$lines[$i-1]);
         my( $distanceB, $bearingB ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeB, $GPSLongitudeB );
         $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\' \'-GPSImgDirection=$bearingM\'");
      }
      elsif($i == $size-1) { # last streetview B = Befores
         ($FileNameB, $GPSLatitudeB, $GPSLongitudeB, $GPSAltitudeB,  $GPSDateStampB, $GPSTimeStampB) = split(' ',$lines[$i-1]);
         my( $distanceB, $bearingB ) = $geo->to( $GPSLatitude, $GPSLongitude, $GPSLatitudeB, $GPSLongitudeB );
         $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\' \'-GPSImgDirection=$bearingB\'");
      }
} # end for

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #9 on: May 12, 2010, 08:54:44 AM »
[Originally posted by exiftool on 2010-01-04 13:16:10-08]

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

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #10 on: May 12, 2010, 08:54:44 AM »
[Originally posted by janmartin on 2010-01-04 14:12:41-08]

Phil,

I am new to the Perl scene.

May I ask for a hint where to look for interested volunteers?

Thanks,

Jan

Archive

  • Newbie
  • *
  • Posts: 0
Re: How to add the bearing to a jpg?
« Reply #11 on: May 12, 2010, 08:54:44 AM »
[Originally posted by exiftool on 2010-01-04 14:43:37-08]

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