Convert facetags from WLPG to Picasa

Started by raldo, August 27, 2012, 05:53:31 PM

Previous topic - Next topic

raldo

I've tagged a whole bunch of photos in WLPG and I'd like to convert the XMP to Picasa.

Any starting hints? Is it even possible

Phil Harvey

Where does Picasa store this information?  I fear that it may be in a .ini file, which would require a bit of Perl scripting to write.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

gcoupe

#2
The latest version of Picasa (3.9) uses the proposed Face Region standard of the Metadata Working Group to store XMP metadata into JPEG files. It should also read in the Microsoft Person Tag (which includes Microsoft's face region data) from the metadata created by WLPG.

The trick is to force Picasa to then write out the Face Region data into the JPEG files. I think it can be done by selecting all the thumbnails of a given person under "People" then right click and choose "Move to New Person..." and reselect the same name. Clicking on "Choose" then seems to do the updating of the files and also adds the tags for all other people who have been recognised in the affected photos. See this post for more info: http://gcoupe.wordpress.com/2011/12/10/picasa-versus-windows-live-photo-gallery/

Of course, using ExifTool would be safer - Picasa 3.9 still has bugs, and will strip out Canon Makernotes... But I'll leave that to others more competent than I.

raldo

In recent versions of Picasa, the info is stored in the file as XMP.

I have attached a test file with persons Test, Test2 tagged. I can see this in Geosetter and it seems as if persons are in a comma separated list (Region Name). The region parameters are similarly in comma separated lists.

Phil Harvey

It sounds like the easiest solution is to use Picasa if this works.  Otherwise, it should be possible to do this with ExifTool, but would require a bit of effort to create the necessary user-defined tags.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

raldo

It is not possible to use Picasa (as far as I understand from the Picasa forums). At least in Picasa's current state. The reason is that Picasa sees the WLPG tags but additionally recognizes the same faces. So one has to manually remove all of Picasa's new selections.

Phil Harvey

OK then, ExifTool it is.

If you post a (small) image with a couple of faces tagged by WLPG and the same image with the same faces tagged by Picasa I should be able to come up with a user-defined tag that will do this transformation for you.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

raldo


raldo

#8
I have attached an image where the same people are tagged in approximately the same area as they are tagged in the previously posted picasa image.

As far as I understand, the rectangle corners are in normalized coordinates wrt. width and height in both applications.

Thanks!

Phil Harvey

Thanks.  Give me a bit of time to work on this.  I'll try to have something within a day or so.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

raldo

Quote from: Phil Harvey on August 29, 2012, 06:51:05 AM
Thanks.  Give me a bit of time to work on this.  I'll try to have something within a day or so.

- Phil

Great!

Phil Harvey

#11
OK, here you go.  Attached is the config file to do this conversion.  (See the sample config file for installation instructions.)

With this config file installed, the following command will translate WLPG regions to standard MWG:

exiftool "-regioninfo<myregion" FILE

(where FILE is one or more file and/or directory names)

Here is what the attached config file looks like:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyRegion => {
            Require => {
                0 => 'RegionInfoMP',
                1 => 'ImageWidth',
                2 => 'ImageHeight',
            },
            ValueConv => q{
                my ($rgn, @newRgns);
                foreach $rgn (@{$val[0]{Regions}}) {
                    my @rect = split /\s*,\s*/, $$rgn{Rectangle};
                    my %newRgn = (
                        Area => {
                            X => $rect[0] + $rect[2]/2,
                            Y => $rect[1] + $rect[3]/2,
                            W => $rect[2],
                            H => $rect[3],
                            Unit => 'normalized',
                        },
                        Name => $$rgn{PersonDisplayName},
                        Type => 'Face',
                    );
                    push @newRgns, \%newRgn;
                }
                return {
                    AppliedToDimensions => { W => $val[1], H => $val[2], Unit => 'pixel' },
                    RegionList => \@newRgns,
                };
            },
        },
    },
);
1;  #end


The code in this ValueConv is quite advanced because it deals with XMP structures, which are tricky.

Let me know how this goes.  It looks to me like the region coordinates use the same coordinate system, but they were just different enough to worry me a bit.  Hopefully this works.

- Phil

Edit:  I checked the Microsoft and MWG specifications, and the X/Y position is top/left for WLPG but center for MWG, so a coordinate transformation was necessary after all.  I have fixed the config file accordingly and attached the new version.

Edit2: Removed the -struct option from the command since it is unnecessary when copying tags (although you must use it when just extracting information if you want to see any of the structures).
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

raldo

Thanks, I'll experiment with this over the weekend.

Phil Harvey

Attached is a config file that defines another tag to do the reverse conversion.  Here are the commands to use with this config file:

1) Convert from MP WLPG regions to MWG regions:

exiftool -config ExifTool_config_convert_regions "-regioninfo<myregion" FILE

2) Convert from MWG to WLPG regions:

exiftool -config ExifTool_config_convert_regions "-regioninfomp<myregionmmp" FILE

You can avoid the -config option in these commands by activating this config file as the default configuration.  See the instructions in the sample config file for details.

In case people are interested, this is the definition of the new user-defined tag to convert from MWG to WLPG regions:

        MyRegionMP => {
            Require => 'RegionInfo',
            ValueConv => q{
                my ($rgn, @newRgns);
                foreach $rgn (@{$val[0]{RegionList}}) {
                    my @rect = @{$$rgn{Area}}{'X','Y','W','H'};
                    $rect[0] -= $rect[2]/2;
                    $rect[1] -= $rect[3]/2;
                    push @newRgns, {
                        PersonDisplayName => $$rgn{Name},
                        Rectangle => join(', ', @rect),
                    };
                }
                return { Regions => \@newRgns };
            },
        },


Note that this will only work for rectangular regions.  The MWG specification also allows circles and points, but these are not supported by the Microsoft MP region structure.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

SonnyJim66

Thanks for providing this.  I downloaded the config file and renamed it to make it my default config.

Conversion from Windows Photo Gallery to MWG tags seems to work fine, but each time I try to convert a file with people tags created by Picasa, I get an error message:

Warning: No writable tags set from MWG.jpg

I used Picasa 3.9.0 (Build 136.09.0) on Windows 7 SP1 (64-bit) to tag the faces, and I'm using the following syntax to perform the update:

exiftool "-regioninfomp<myregionmmp" MWG.jpg

Any ideas what I might be doing wrong?

Thanks.