如何在Java中从JPEG读取XMP面部数据 [英] How to read XMP face data from JPEG in Java

查看:546
本文介绍了如何在Java中从JPEG读取XMP面部数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将Picasa的面部数据保存在JPEG文件中(在XMP中),现在我试图用Java读取该信息.到目前为止,我失败了,将不胜感激.

I have saved Picasa's face data inside my JPEG files (in XMP) and now I am trying to read that information in Java. So far I am failing and help would be much appreciated.

我正在尝试使用元数据提取器库(尽管有其他解决方案)也可以).我可以阅读基本信息(例如日期,图像大小等),但是我在提取其他数据时迷失了方向.这是到目前为止我得到的:

I am trying to use metadata-extractor library (though any other solution would also be fine). I can read the basic information (like the date, the image size etc.), but I am lost at extracting the additional data. This is what I get so far:

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"等.

I do not understand how to get to these stArea:w, mwg-rs:Type = "Face", etc.

推荐答案

和往常一样,我刚发布

As usual, right after posting I've found a solution. I'll list it below to have it here.

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
}

我在这里不喜欢的是,它遍历所有属性,而不仅仅是读取必需的属性.还有更好(更快)的解决方案吗?

What I do not like here is that it iterates through all properties instead of just reading the required ones. Any better (faster) solution?

这篇关于如何在Java中从JPEG读取XMP面部数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆