Reading "People Tags" inserted by Windows Live Photo Gallery
Asked Answered
J

2

4

Photo Gallery gives you the ability to mark a person's face and apply a tag to it. I understand it inserts tags directly into the file rather than store it off in a database or accompanying metafile anywhere.

So if that's true, what data is it inserting and how is it formatted?

Jamesjamesian answered 25/9, 2009 at 2:44 Comment(0)
J
4

Here's the code I wanted. It's in C#.

        public void ReadWLPGRegions(string sourceFile)
    {
        string microsoftRegions = @"/xmp/RegionInfo/Regions";
        string microsoftPersonDisplayName = @"/PersonDisplayName";
        string microsoftRectangle = @"/Rectangle";
        BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;

        using (Stream sourceStream = File.Open(sourceFile, FileMode.Open, FileAccess.Read))
        {
            BitmapDecoder sourceDecoder = BitmapDecoder.Create(sourceStream, createOptions, BitmapCacheOption.None);

            // Check source has valid frames
            if (sourceDecoder.Frames[0] != null && sourceDecoder.Frames[0].Metadata != null)
            {
                BitmapMetadata sourceMetadata = sourceDecoder.Frames[0].Metadata as BitmapMetadata;

                // Check there is a RegionInfo
                if (sourceMetadata.ContainsQuery(microsoftRegions))
                {
                    BitmapMetadata regionsMetadata = sourceMetadata.GetQuery(microsoftRegions) as BitmapMetadata;

                    // Loop through each Region
                    foreach (string regionQuery in regionsMetadata)
                    {
                        string regionFullQuery = microsoftRegions + regionQuery;

                        // Query for all the data for this region
                        BitmapMetadata regionMetadata = sourceMetadata.GetQuery(regionFullQuery) as BitmapMetadata;

                        if (regionMetadata != null)
                        {
                            if (regionMetadata.ContainsQuery(microsoftPersonDisplayName) &&
                                regionMetadata.ContainsQuery(microsoftRectangle))
                            {
                                Console.Writeline( regionMetadata.GetQuery(microsoftRectangle).ToString()));
                                 Console.WriteLine(regionMetadata.GetQuery(microsoftPersonDisplayName).ToString()));
                            }

                        }
                    }
                }
            }
        }
    }
Jamesjamesian answered 27/9, 2009 at 22:17 Comment(2)
Have you come across a similar solution in Python?Dullard
Nope. The code relies pretty heavily on Microsoft structures, and I'm not aware of any Python library with the equivalents.Jamesjamesian
M
1

When possible, Windows Live Photo Gallery uses XMP to write metadata to picture files. See Metadata and the Windows Vista Photo Gallery for details.

Myungmyxedema answered 25/9, 2009 at 8:44 Comment(2)
At what byte offset does the XMP start?Jamesjamesian
In the Wikipedia article I linked above, it lists "Location in file types." For example, a JPEG has XMP data in "Application segment 1 (0xFFE1) with segment header 'ns.adobe.com/xap/1.0\x00'".Myungmyxedema

© 2022 - 2024 — McMap. All rights reserved.