I have a series of JPEGS captured during an aerial patrol. These JPEGS have metadata stored within JPEG, this metadata includes the GPSInfo and other data.
I am trying to extract this information into a format I can use (csv etc.). I am also going to try and implement this in a Python script that will run on a shared virtual machine, possibly in FME.
I am able to run the Python PIL library and extract out much of the information I need. See below:
import PIL.Image
import PIL.ExifTags
from PIL import Image, ExifTags
from PIL.ExifTags import GPSTAGS
from PIL.ExifTags import TAGS
from os import walk
import os
import pandas as pd
import os
from datetime import datetime
def get_exif(filepath):
image = Image.open(filepath)
image.verify()
return image._getexif()
The following falls under a Main() method
for filename in os.listdir(direct):
if filename.endswith(".jpg"):
print (i)
filepath = os.path.join(direct, filename)#
attribs = []
exif = get_exif(filepath)
fields = ['GPSInfo', 'Model', 'ExposureTime', 'FocalLength', 'Software', 'DateTime', 'DateTimeDigitised']
exifData = {}
for f in fields:
for tag, value in exif.items():
decodedTag = ExifTags.TAGS.get(tag, tag)
if decodedTag == f:
exifData["File"] = filename
if decodedTag == 'GPSInfo':
exifData["Y"] = value[2]
exifData["X"] = value[4]
exifData["Z"] = value[6]
continue
else:
exifData[decodedTag] = value
continue
df = df.append(exifData, ignore_index = True)
i +=1
I had initially extracted all tags from the Exif, and then created a list to filter only the tags I wanted.
On seeing the output, a colleague asked for the Pitch, Roll and Yaw to be extracted as well, but these were not in the original list of tags I extracted.
An image was run through the commandline ExifTools.exe, and the following data formed part of the output.
GPS Roll : -100.509252
GPS Pitch : -66.017852017852
GPS Yaw : 84.001227001227
Is there a way to have the PIL library return these values for Yaw, Pitch and Roll?
I cannot use the commandline on the machine I want to deploy this and I cannot add any new transformers to my FME Installation on this machine.
Best Answer
I think it is a matter of the python implementation. If you have a look at the
ExifTags.py
the tags are not listed. May that's because the tags are not standardized. If you have a look in the exiv2 GPSInfo Group, the tags are also not listed.I had a look into the
Image::ExifTool
source code, there are about 100 data formats addressed or handled:When I filter the modules for the
GPSRoll
tag, I find advices like:So it seems that the attitude data tagging is made on a "Thin Ice" standard and you have to enable some user defined tag capabilities. When I made a test against image with Roll, Pitch and Yaw tags from a PhaseOne Camera image (which I often use), the library
Image::ExifTool
can read the tags with complete different names (GPSIMURoll ...). At the moment I don't know how it works.According to the FME constraints, is it possible to use the either
exiftool
or theImage::ExifTool
library either by ashell-out
and parse the resulting code like:or tailor a IPC specific call in Perl to get the info's.
Test dataset
The test dataset is from a PhaseOne iXM-RS150F aerial camara. The IIQ format is a special image format based on 2 page TIF with a overview image TIF coded and the large RAW dataset block. Metadata are embedded Tif specific present in the IFD.
Python Pillow (PIL fork)
Here is my Python test code (I'm not a crack in python coding), which is hopefully similar to the Perl code below. Unfortunatly PIL cannot read or decode the exif directory of my IIQ image. May it works for you with the JPG.
While it in Perl it works (see the test below). May be as mentioned, that's because the library supports a large number of also strange or vendor related (raw) image formats (..see table of images supported).
Python script
Resulting output from the Python script
Perl Family
Exif Tool
Extract GPS tags with the
exiftool
(Perl5 related code base). Theexiftool
inserts some spaces to make the matter better human readable. In the machine prepared dictionary these space disappear.Perl script -- library
Image::ExifTool
Extract the GPS tags with the perl library
Image::ExifTool
where theExifTool
belongs to.Resulting output from the Perl script