0.内容概览
1.Exempi工具安装
1.1 源码获取
- (1) 官网源码获取
- (2) gitlab源码获取
1.2 依赖库获取
- (1) 下载expat源码:expat源码地址
- (2) 源码解压:
# 1.进入第三方库expat路径
>> cd exempi/third-party/expat
# 2.将下载的expat源码放入当前路径,并对源码解压缩
>> tar -xf expat-2.6.4.tar.xz
# 3.移动解压文件到根目录
>> cd expat-2.6.4 && mv * ../
# 4.删除无用文件及目录
>> cd .. && rm -r expat-2.6.4 && rm expat-2.6.4.tar.xz
1.3 编译安装
>> cd exempi && ./autogen.sh && ./configure
>> make -j 8 && sudo make install
2.python-xmp-toolkit工具安装
2.1 直接pip安装
>> pip install python-xmp-toolkit
2.2 源码安装
>> git clone git@github.com:python-xmp-toolkit/python-xmp-toolkit.git
>> cd python-xmp-toolkit && python setup.py install
3.python-xmp-toolkit工具使用
3.1 简单获取xmp信息
from libxmp import XMPFiles, consts
# 1.打开图片
xmpfile = XMPFiles(file_path="DJI_0161.JPG", open_forupdate=True)
# 2.获取xmp信息
xmp = xmpfile.get_xmp()
# 3.打印xmp信息
print(xmp.serialize_to_str())
# 4.关闭xmpfile
xmpfile.close_file()
输出结果:
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Exempi + XMP Core 6.0.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:drone-dji="http://www.dji.com/drone-dji/1.0/"
xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/"
xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
xmlns:exif="http://ns.adobe.com/exif/1.0/"
xmlns:exifEX="http://cipa.jp/exif/1.0/"
xmlns:aux="http://ns.adobe.com/exif/1.0/aux/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
<xmp:ModifyDate>2022-07-14</xmp:ModifyDate>
<xmp:CreateDate>2022-07-14</xmp:CreateDate>
<xmp:CreatorTool>v01.09.1759</xmp:CreatorTool>
<dc:format>image/jpg</dc:format>
<dc:description>
<rdf:Alt>
<rdf:li xml:lang="x-default">DCIM\100MEDIA\DJI_0161.JPG</rdf:li>
</rdf:Alt>
</dc:description>
<drone-dji:AbsoluteAltitude>+72.40</drone-dji:AbsoluteAltitude>
<drone-dji:RelativeAltitude>+21.23</drone-dji:RelativeAltitude>
<drone-dji:GpsLatitude>29.69077918</drone-dji:GpsLatitude>
<drone-dji:GpsLongtitude>121.25295842</drone-dji:GpsLongtitude>
<drone-dji:GimbalRollDegree>+0.00</drone-dji:GimbalRollDegree>
<drone-dji:GimbalYawDegree>-22.50</drone-dji:GimbalYawDegree>
<drone-dji:GimbalPitchDegree>-10.10</drone-dji:GimbalPitchDegree>
<drone-dji:FlightRollDegree>+0.00</drone-dji:FlightRollDegree>
<drone-dji:FlightYawDegree>-22.60</drone-dji:FlightYawDegree>
<drone-dji:FlightPitchDegree>+3.20</drone-dji:FlightPitchDegree>
<drone-dji:FlightXSpeed>+0.00</drone-dji:FlightXSpeed>
<drone-dji:FlightYSpeed>+0.00</drone-dji:FlightYSpeed>
<drone-dji:FlightZSpeed>+0.00</drone-dji:FlightZSpeed>
<drone-dji:CamReverse>0</drone-dji:CamReverse>
<drone-dji:GimbalReverse>0</drone-dji:GimbalReverse>
<drone-dji:SelfData>Undefined</drone-dji:SelfData>
<drone-dji:CalibratedFocalLength>3666.666504</drone-dji:CalibratedFocalLength>
<drone-dji:CalibratedOpticalCenterX>2736.000000</drone-dji:CalibratedOpticalCenterX>
<drone-dji:CalibratedOpticalCenterY>1824.000000</drone-dji:CalibratedOpticalCenterY>
<drone-dji:RtkFlag>50</drone-dji:RtkFlag>
<drone-dji:RtkStdLon>0.01200</drone-dji:RtkStdLon>
<drone-dji:RtkStdLat>0.01169</drone-dji:RtkStdLat>
<drone-dji:RtkStdHgt>0.03219</drone-dji:RtkStdHgt>
<drone-dji:DewarpFlag>1</drone-dji:DewarpFlag>
<drone-dji:PhotoDiff>34YDK3X001906M20220714024043</drone-dji:PhotoDiff>
<crs:Version>7.0</crs:Version>
<crs:HasSettings>False</crs:HasSettings>
<crs:HasCrop>False</crs:HasCrop>
<crs:AlreadyApplied>False</crs:AlreadyApplied>
<tiff:Orientation>1</tiff:Orientation>
<tiff:XResolution>72/1</tiff:XResolution>
<tiff:YResolution>72/1</tiff:YResolution>
<tiff:ResolutionUnit>2</tiff:ResolutionUnit>
<tiff:YCbCrPositioning>1</tiff:YCbCrPositioning>
<tiff:Make>DJI</tiff:Make>
<tiff:Model>FC6310R</tiff:Model>
<exif:ColorSpace>1</exif:ColorSpace>
<exif:CompressedBitsPerPixel>8291635/2495232</exif:CompressedBitsPerPixel>
<exif:PixelXDimension>5472</exif:PixelXDimension>
<exif:PixelYDimension>3648</exif:PixelYDimension>
<exif:ExposureTime>1562/1000000</exif:ExposureTime>
<exif:FNumber>630/100</exif:FNumber>
<exif:ExposureProgram>2</exif:ExposureProgram>
<exif:ShutterSpeedValue>-9321/-1000</exif:ShutterSpeedValue>
<exif:ApertureValue>531/100</exif:ApertureValue>
<exif:ExposureBiasValue>0/32</exif:ExposureBiasValue>
<exif:MaxApertureValue>297/100</exif:MaxApertureValue>
<exif:SubjectDistance>0/100</exif:SubjectDistance>
<exif:MeteringMode>1</exif:MeteringMode>
<exif:LightSource>1</exif:LightSource>
<exif:FocalLength>880/100</exif:FocalLength>
<exif:ExposureIndex>0/0</exif:ExposureIndex>
<exif:CustomRendered>0</exif:CustomRendered>
<exif:ExposureMode>0</exif:ExposureMode>
<exif:WhiteBalance>1</exif:WhiteBalance>
<exif:DigitalZoomRatio>0/0</exif:DigitalZoomRatio>
<exif:FocalLengthIn35mmFilm>24</exif:FocalLengthIn35mmFilm>
<exif:SceneCaptureType>0</exif:SceneCaptureType>
<exif:GainControl>0</exif:GainControl>
<exif:Contrast>0</exif:Contrast>
<exif:Saturation>0</exif:Saturation>
<exif:Sharpness>0</exif:Sharpness>
<exif:SubjectDistanceRange>0</exif:SubjectDistanceRange>
<exif:GPSAltitudeRef>0</exif:GPSAltitudeRef>
<exif:GPSAltitude>72402/1000</exif:GPSAltitude>
<exif:DateTimeOriginal>2022-07-14T10:40:25</exif:DateTimeOriginal>
<exif:ISOSpeedRatings>
<rdf:Seq>
<rdf:li>100</rdf:li>
</rdf:Seq>
</exif:ISOSpeedRatings>
<exif:ExifVersion>0230</exif:ExifVersion>
<exif:FlashpixVersion>0010</exif:FlashpixVersion>
<exif:ComponentsConfiguration>
<rdf:Seq>
<rdf:li>0</rdf:li>
<rdf:li>3</rdf:li>
<rdf:li>2</rdf:li>
<rdf:li>1</rdf:li>
</rdf:Seq>
</exif:ComponentsConfiguration>
<exif:Flash rdf:parseType="Resource">
<exif:Fired>False</exif:Fired>
<exif:Return>0</exif:Return>
<exif:Mode>0</exif:Mode>
<exif:Function>True</exif:Function>
<exif:RedEyeMode>False</exif:RedEyeMode>
</exif:Flash>
<exif:FileSource>3</exif:FileSource>
<exif:SceneType>1</exif:SceneType>
<exif:GPSVersionID>2.3.0.0</exif:GPSVersionID>
<exif:GPSLatitude>29,41.4468N</exif:GPSLatitude>
<exif:GPSLongitude>121,15.1775E</exif:GPSLongitude>
<exifEX:BodySerialNumber>4ae74aee3d58a0ac47a32a630ceeb9eb</exifEX:BodySerialNumber>
<exifEX:PhotographicSensitivity>100</exifEX:PhotographicSensitivity>
<aux:SerialNumber>4ae74aee3d58a0ac47a32a630ceeb9eb</aux:SerialNumber>
<photoshop:DateCreated>2022-07-14T10:40:25</photoshop:DateCreated>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
3.2 获取和设置属性
'''
Author: chenjingyu
Date: 2024-11-28 15:14:13
Contact: 2458006466@qq.com
Description: test_xmp
'''
from libxmp import XMPFiles, XMPMeta, consts
XMP_NS_DJI = "http://www.dji.com/drone-dji/1.0/"
XMPMeta.register_namespace(XMP_NS_DJI, "drone-dji")
# 1.打开图片
xmpfile = XMPFiles(file_path="DJI_0161.JPG", open_forupdate=True)
# 2.获取xmp信息
xmp = xmpfile.get_xmp()
# 3.获取属性并设置属性
if xmp.does_property_exist(consts.XMP_NS_EXIF, "PixelXDimension"):
print("PixelXDimension exits")
x = xmp.get_property_float(consts.XMP_NS_EXIF, "PixelXDimension")
print(f"PixelXDimension: {x}")
if xmp.does_property_exist(XMP_NS_DJI, "PixelYDimension"):
print("PixelYDimension exits")
y = xmp.get_property_float(XMP_NS_DJI, "PixelYDimension")
print(f"PixelYDimension: {y}")
if xmp.does_property_exist(XMP_NS_DJI, "GPSLongitude"):
print("GPSLongitude exits")
lon = xmp.get_property_float(XMP_NS_DJI, "GPSLongitude")
print(f"GPSLongitude: {lon}")
if xmp.does_property_exist(XMP_NS_DJI, "GpsLatitude"):
print("GpsLatitude exits")
lat = xmp.get_property_float(XMP_NS_DJI, "GpsLatitude")
print(f"GpsLatitude: {lat}")
xmp.set_property_float(XMP_NS_DJI, "GpsLatitude", 50.0)
lat = xmp.get_property_float(XMP_NS_DJI, "GpsLatitude")
print(f"GpsLatitude: {lat}")
if xmp.does_property_exist(XMP_NS_DJI, "GimbalRollDegree"):
print("GimbalRollDegree exits")
roll = xmp.get_property_float(XMP_NS_DJI, "GimbalRollDegree")
print(f"GimbalRollDegree: {roll}")
if xmp.does_property_exist(XMP_NS_DJI, "GimbalYawDegree"):
print("GimbalYawDegree exits")
yaw = xmp.get_property_float(XMP_NS_DJI, "GimbalYawDegree")
print(f"GimbalYawDegree: {yaw}")
if xmp.does_property_exist(XMP_NS_DJI, "GimbalPitchDegree"):
print("GimbalPitchDegree exits")
pitch = xmp.get_property_float(XMP_NS_DJI, "GimbalPitchDegree")
print(f"GimbalPitchDegree: {pitch}")
# 4.关闭xmpfile
xmpfile.close_file()
输出结果:
PixelXDimension exits
PixelXDimension: 5472.0
GpsLatitude exits
GpsLatitude: 29.69077918
GpsLatitude: 50.0
GimbalRollDegree exits
GimbalRollDegree: 0.0
GimbalYawDegree exits
GimbalYawDegree: -22.5
GimbalPitchDegree exits
GimbalPitchDegree: -10.1