在Java中,如何从图像中提取与相机相关的信息? [英] In java how can I extract camera related information from an image?

查看:191
本文介绍了在Java中,如何从图像中提取与相机相关的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用Java从jpg中提取与相机相关的信息的方法.我环顾四周,但无法找到解决问题的方法.我要从Mac(OS X 10.7)上的Aperture导出照片,并希望使用文件信息中可用的Aperture数据.

I am looking to extract the camera related information from a jpg using Java. I have looked around but have not been able to find a solution to my problem. I am exporting my photos from Aperture on my mac (OS X 10.7) and want to use the data from Aperture that is available in the file info.

有什么想法吗?

我希望从这样的照片中提取尺寸和关键词:80.167.88.49/masters/test.html.目前,当我尝试使用元数据提取器时出现异常.我不知道Aperture是否添加了无法处理的信息,但会在Aperture的所有照片上引发异常.

I am looking to have Dimensions and Key Words extracted from photos like this one: 80.167.88.49/masters/test.html. Currently i get an exception when trying to use the Metadata Extractor. I don't know if Aperture is adding information that cannot be handled but it throws an exception on all photos from Aperture.

Exception in thread "main" java.lang.NoClassDefFoundError: com/adobe/xmp/XMPException
    at com.drew.imaging.jpeg.JpegMetadataReader.extractMetadataFromJpegSegmentReader(Unknown Source)
    at com.drew.imaging.jpeg.JpegMetadataReader.readMetadata(Unknown Source)
    at com.drew.imaging.ImageMetadataReader.readMetadata(Unknown Source)
    at com.drew.imaging.ImageMetadataReader.readMetadata(Unknown Source)
    at ImageScaler.main(ImageScaler.java:141)
Caused by: java.lang.ClassNotFoundException: com.adobe.xmp.XMPException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 5 more

代码:

public static void main (String[] args){

    File image = new File("/Users/peterla/Desktop/P8214462.jpg");

    Metadata metadata = null;
    try {
    metadata = ImageMetadataReader.readMetadata(image);
    } catch (ImageProcessingException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    Directory directory;

    // Keywords
    directory = metadata.getDirectory(IptcDirectory.class);
    String keywords[] = directory.getStringArray(IptcDirectory.TAG_KEYWORDS);

    // Dimensions
    directory = metadata.getDirectory(JpegDirectory.class);     
    String height = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
    String width = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);     
}

推荐答案

元数据提取器具有一个简单的界面,可以从许多数字图像格式中读取几种类型的元数据.这包括jpeg图片中使用的 EXIF 元数据格式.该库具有良好的Javadoc样式文档.

Metadata Extractor has a simple interface for reading several types of metadata from many digital image formats. This includes the EXIF metadata format used in jpeg images. The library has good Javadoc style documentation.

该库的主要入口是 ImageMetadataReader 对象.

The primary entry point into the library is the ImageMetadataReader object.

入门页有一个不错的介绍,其中包括一个不错的介绍.如何从EXIF格式元数据中获取特定标签的值的示例.

The Getting Started page has a nice intro, including a nice example of how to get a value for a specific tag from EXIF format metadata.

更新:提取关键字和维度的示例

Directory directory;
// Keywords
directory = metadata.getDirectory(IptcDirectory.class);
String keywords[] = directory.getStringArray(IptcDirectory.TAG_KEYWORDS);

// Dimensions
directory = metadata.getDirectory(JpegDirectory.class);     
String height = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
String width = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);

替代

替代方法包括内置的Java ImageIO 库和 Sanselan .

Alternatives include the builtin java ImageIO library and Sanselan.

这篇关于在Java中,如何从图像中提取与相机相关的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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