使用 metadata-extractor-dotnet 提取 Microsoft 照片 XMP 人物标签

时间:2021-01-25 13:45:59

标签: .net metadata-extractor

我正在尝试使用带有 C# 的 metadata-extractor-dotnet 从 JEPG 文件中读取 Microsoft 照片 XMP 人物标签(名称和矩形)。到目前为止,我只能使用某种hacky代码来提取人名。我想知道是否有更简洁的方法。

背景 1:我正在尝试读取这些 XMP 元数据值:https://exiftool.org/TagNames/Microsoft.html -> Microsoft MP 标签 -> RegionPersonDisplayName & RegionRectangle

背景 2:当使用 metadata-extractor-dotnet (xmpDirectory.XmpMeta.Properties) 迭代 JPEG 中的 XML 值时,我看到以下值:

  • 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,值=0.297101、0.283765、0.164855、0.248295,命名空间: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#

我的工作和提取人名的hacky代码如下所示:

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()
}

在我的代码中,array1 数组似乎没有保存任何可用数据。所以我只用它的存在作为一个指标,表明在不同的查询下有更多的数据可用。

知道如何直接获取一个“东西”数组,我可以直接访问 PersonDisplayName 和 Rectangle 吗?

0 个答案:

没有答案
相关问题