Created
July 16, 2021 08:26
-
-
Save FreeFly19/09f2f54a4e60c9df0a1bd276daf80efc to your computer and use it in GitHub Desktop.
DJI Image metadata parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ai.spector; | |
import com.adobe.xmp.XMPIterator; | |
import com.adobe.xmp.XMPMeta; | |
import com.adobe.xmp.properties.XMPPropertyInfo; | |
import com.drew.imaging.ImageMetadataReader; | |
import com.drew.metadata.Directory; | |
import com.drew.metadata.Metadata; | |
import com.drew.metadata.Tag; | |
import com.drew.metadata.xmp.XmpDirectory; | |
import java.io.File; | |
import java.util.Collection; | |
public class CoreApplication { | |
public static void main(String[] args) throws Exception { | |
File imgFile = new File("/media/freefly19/ML/1_spector_andy_data/BASE IMAGES/DJI_0002.JPG"); | |
Metadata metadata = ImageMetadataReader.readMetadata(imgFile); | |
Iterable<Directory> directories = metadata.getDirectories(); | |
for (Directory directory : directories) { | |
System.out.println(); | |
for (Tag tag : directory.getTags()) { | |
System.out.println("'" + directory.getName() + "/" + tag.getTagName() + "'\t" + directory.getString(tag.getTagType())); | |
} | |
} | |
Collection<XmpDirectory> directoriesOfType = metadata.getDirectoriesOfType(XmpDirectory.class); | |
for (XmpDirectory xmpDirectory : directoriesOfType) { | |
XMPMeta xmpMeta = xmpDirectory.getXMPMeta(); | |
XMPIterator itr = xmpMeta.iterator(); | |
while (itr.hasNext()) { | |
XMPPropertyInfo pi = (XMPPropertyInfo) itr.next(); | |
if (pi != null && pi.getPath() != null) { | |
System.out.println(xmpDirectory.getName() + "/" + pi.getPath() + ":\t" + pi.getValue()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment