如何在Java中从JPEG中读取XMP人脸数据
我已经将Picasa的面部数据保存在我的JPEG文件中(在XMP中),现在我正在尝试用Java读取这些信息。到目前为止,我失败了,我将非常感谢你的帮助 我正在尝试使用这个库(尽管任何其他解决方案也可以)。我可以读取基本信息(如日期、图像大小等),但我无法提取附加数据。到目前为止,我得到的是:如何在Java中从JPEG中读取XMP人脸数据,java,picasa,xmp,metadata-extractor,Java,Picasa,Xmp,Metadata Extractor,我已经将Picasa的面部数据保存在我的JPEG文件中(在XMP中),现在我正在尝试用Java读取这些信息。到目前为止,我失败了,我将非常感谢你的帮助 我正在尝试使用这个库(尽管任何其他解决方案也可以)。我可以读取基本信息(如日期、图像大小等),但我无法提取附加数据。到目前为止,我得到的是: File file -- this is my JPEG file Metadata metadata = JpegMetadataReader.readMetadata(file); XmpDirect
File file -- this is my JPEG file
Metadata metadata = JpegMetadataReader.readMetadata(file);
XmpDirectory xmpDirectory = metadata.getDirectory(XmpDirectory.class);
XMPMeta xmpMeta = xmpDirectory.getXMPMeta();
System.out.println(xmpMeta.dumpObject());
结果:
ROOT NODE
http://www.metadataworkinggroup.com/schemas/regions/ = "mwg-rs:" (0x80000000 : SCHEMA_NODE)
mwg-rs:Regions (0x100 : STRUCT)
mwg-rs:AppliedToDimensions (0x100 : STRUCT)
stDim:h = "2793"
stDim:unit = "pixel"
stDim:w = "2047"
mwg-rs:RegionList (0x200 : ARRAY)
[1] (0x100 : STRUCT)
mwg-rs:Area (0x100 : STRUCT)
stArea:h = "0.69531"
stArea:unit = "normalized"
stArea:w = "0.790425"
stArea:x = "0.491451"
stArea:y = "0.41783"
mwg-rs:Name = "abcde"
mwg-rs:Type = "Face"
http://ns.adobe.com/xap/1.0/ = "xmp:" (0x80000000 : SCHEMA_NODE)
xmp:ModifyDate = "2014-04-06T19:43:24+01:00"
我不知道如何进入这些stArea:w,mwg rs:Type=“Face”,等等。像往常一样,在我发布完之后。我会把它列在下面,放在这里
try {
Metadata metadata = ImageMetadataReader.readMetadata(imageFile);
XmpDirectory xmpDirectory = metadata.getDirectory(XmpDirectory.class);
XMPMeta xmpMeta = xmpDirectory.getXMPMeta();
XMPIterator itr = xmpMeta.iterator();
while (itr.hasNext()) {
XMPPropertyInfo pi = (XMPPropertyInfo) itr.next();
if (pi != null && pi.getPath() != null) {
if ((pi.getPath().endsWith("stArea:w")) || (pi.getPath().endsWith("mwg-rs:Name")) || (pi.getPath().endsWith("stArea:h")))
System.out.println(pi.getValue().toString());
}
}
} catch (final NullPointerException npe) {
// ignore
}
这里我不喜欢的是它遍历所有属性,而不是只读取所需的属性。有更好(更快)的解决方案吗