0

I'm trying to extract an xml blob in the header data from an image with the following code (a real stab in the dark):

import exifread
Open image file for reading (binary mode)
open('img.jpg', 'rb')

tags = exifread.process_file(f)
for tag in tags.keys():
if tag not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'):
print ("Key: %s, value %s") % (tag, tags[tag])

print(tags)

however I get the following message:

==== RESTART: C:/Users/richie/Desktop/work/exif_read4.py ============
{}
>>>

I know the file contains data in the header, but its possible its not in exif format. Below is an example of the info as they appear in Imagej:

[JpegComment] Jpeg Comment: <?xml version="1.0" encoding="utf-8"?>
<image time="15:27:56.763207" date="2016.02.03" acq_index="3692">
<acquisition>
    <exposure>10000</exposure>
    <sensor_digital_gain>4</sensor_digital_gain>
    <aperture>4</aperture>
    <focus>68</focus>
    <digital_gain>1</digital_gain>
    <name>Photo_pose</name>
    <camera_session_name>EXI-55-retest-3</camera_session_name>
</acquisition>
<errors>

Can anyone think of a way of extracting this data?

Richie Close
  • 77
  • 2
  • 11
  • There are plenty of tools - `jhead`, `exiftool`, `ImageMagick`... those are in increasing order functionality and difficulty to install. – Mark Setchell Feb 10 '16 at 22:08
  • From the looks of the ExifRead docs, it seems that it only extracts EXIF data, not any other type of metadata (XMP, IPTC). While I'm not familiar with how Imagej works, the output seems to indicate that the data you want is in a Jpeg comment, which would be an unusual place for xml data to be. You might look for a python package with more complete metadata handling. A quick google search pulled up [hachoir-metadata](https://pypi.python.org/pypi/hachoir-metadata/1.3.3) which looks like it could handle your data. – StarGeek Feb 11 '16 at 00:52
  • There's `exiv2` as well, btw. – Mark Setchell Feb 11 '16 at 20:53

1 Answers1

0

Thanks guys - given the nature of the header information I'm dealing with, going to go with the exiftool.exe in conjunction with the pyexifinfo library. I'll experiment a little with it and see what it gets me.

Richie Close
  • 77
  • 2
  • 11