You can record the shooting date and time and location in a JPG file of the photo. Tag information may be written on photos taken with drones, etc. They seem to be recorded according to a common format. The purpose is to read and write them.
There are many descriptions about GPS Exif. So I'll make a note of xmp, which seems to be less informative here. I can read it, but I'm not good at writing it. (Tears)
Apparently, it was defined by Adobe and used to add information to each file in XML format text to the file's header. I don't know the details. ^^;)
So, for example, if you look at it with the less command, you can read the XML part of the text as it is. My uncle is in a Linux environment (WSL), --Open the file with less ――You will be asked "It's binary, but will you open it?", So say Yes. --Searching for the string xml (slash xml return),
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="DJI Meta Data"
xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
xmlns:exif="http://ns.adobe.com/exif/1.0/"
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/"
xmlns:drone-dji="http://www.dji.com/drone-dji/1.0/"
xmp:ModifyDate="2018-12-14"
xmp:CreateDate="2018-12-14"
tiff:Make="DJI"
tiff:Model="FC6310R"
dc:format="image/jpg"
drone-dji:AbsoluteAltitude="+255.92"
...
Looks like. The purpose is to read and write this information.
There are, of course, useful tools.
python3 -m pip install python-xmp-toolkit
The XMP-Toolkit-SDK is also available from Adobe for each source. I wonder if it can be used in embedded or smartphone apps. https://github.com/adobe/XMP-Toolkit-SDK
The usage is written in Doc of python-xmp-toolkit, and I just followed it and there was no problem. .. Make a note.
read_xmp01.py
from libxmp import XMPFiles
xmpfile = XMPFiles( file_path="./100_0020_0001.JPG", open_forupdate=True )
xmp = xmpfile.get_xmp()
If there is no error, you can read it. ^^;) You can check the contents of xmp in various ways.
In the previous sample
tiff:Make="DJI"
There was a line called. I want to get the value "DJI" directly for the key "tiff: Make". For that, two steps are required.
First, get the namespace (URI) of the tiff.
In[]: xmp.get_namespace_for_prefix("tiff")
Out[]: 'http://ns.adobe.com/tiff/1.0/'
There is also a namespace with adobe defined in advance, which can also be referenced from the library.
In []: libxmp.consts.XMP_NS_EXIF
Out[]: 'http://ns.adobe.com/exif/1.0/'
You can also find the variable name directly in "Common Namespaces" in Source. ..
To read the value of the tag tiff: Make, specify the namespace corresponding to the tiff.
In []: xmp.get_property(xmp.get_namespace_for_prefix('tiff'),'Make')
Out[]: 'DJI'
You can prevent errors by checking in advance if the keyword is in the namespace.
In []: xmp.does_property_exist(xmp.get_namespace_for_prefix('tiff'),'TEST')
Out[]: False
To be precise, it should be possible to "rewrite", but in reality. .. ..
First, set the value of xmp.
In []: xmp.set_property(xmp.get_namespace_for_prefix('tiff'),'Make', 'some/makers')
In []: xmp.get_property(xmp.get_namespace_for_prefix('tiff'),'Make')
Out[]: 'some/makers'
It seems that you need to put to xmpfile and close the file to write to the file.
In []: if xmpfile.can_put_xmp(xmp):
...: xmpfile.put_xmp(xmp)
...: xmpfile.close_file()
It should be fine. .. .. The result was not rewritten correctly. I don't know if the procedure is different or it's a bug, but I'll make a note of it for now. No error occurs at run time.
I was in a state where I could only read it for the time being. Below is my task:
--Can you get all the tags in each namespace in advance? --Checking the writing operation
that's all. (2020/08/08)
Recommended Posts