I'm trying to read the Microsoft photo XMP person tags (name & rectangle) from JEPG files using metadata-extractor-dotnet with C#. Until now, I've only managed to extract the person name using kind of hacky code. I'd like to know if there is a cleaner way to do it.
Background 1: I'm trying to read these XMP metadata values: https://exiftool.org/TagNames/Microsoft.html -> Microsoft MP Tags -> RegionPersonDisplayName & RegionRectangle
Background 2: when iterating over the XML values in the JPEG with metadata-extractor-dotnet (xmpDirectory.XmpMeta.Properties
), I see the following values:
- Path=MP:RegionInfo, Value='', namespace=http://ns.microsoft.com/photo/1.2/
- Path=MP:RegionInfo/MPRI:Regions, Value='', namespace=http://ns.microsoft.com/photo/1.2/t/RegionInfo#
- Path=MP:RegionInfo/MPRI:Regions[1], Value='', namespace=''
- Path=MP:RegionInfo/MPRI:Regions[1]/MPReg:Rectangle, Value=0.297101, 0.283765, 0.164855, 0.248295, namespace: http://ns.microsoft.com/photo/1.2/t/Region#
- Path=MP:RegionInfo/MPRI:Regions[1]/MPReg:PersonDisplayName, Value='Peter Mueller',namespace=http://ns.microsoft.com/photo/1.2/t/Region#
My hacky code that works and extracts the person names looks like this:
var array1 = GetXmpArrayOrNull(XmpDirectory?.XmpMeta, "http://ns.microsoft.com/photo/1.2/", "MP:RegionInfo/MPRI:Regions");
if (array1 != null)
{
return array1
.Select((_, i) => XmpDirectory?.XmpMeta?.GetProperty("http://ns.microsoft.com/photo/1.2/", $"MP:RegionInfo/MPRI:Regions[{i + 1}]/MPReg:PersonDisplayName")?.Value)
.Where(s => !string.IsNullOrEmpty(s))
.ToList()
}
In my code, the array1
array does not seem to hold any useable data. So I only use its existence as an indicator that there is more data available under different queries.
Any idea how to directly get an array of "something" where I can directly access the PersonDisplayName and the Rectangle?
question from:
https://stackoverflow.com/questions/65886004/extract-microsoft-photo-xmp-person-tags-with-metadata-extractor-dotnet 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…