Author Topic: Tag Ordering  (Read 2557 times)

Bob Bourg

  • Newbie
  • *
  • Posts: 3
Tag Ordering
« on: February 10, 2018, 02:42:12 PM »
I am having the same problems as described in this post:
http://u88.n24.queensu.ca/exiftool/forum/index.php/topic,7615.msg38628.html#msg38628

I am using the following config file from Phil Harvey to convert face regions from Windows Photo Gallery to MWG:
Code: [Select]
#------------------------------------------------------------------------------
# File:         convert_regions.config
#
# Description:  User-defined Composite tag definitions to allow conversion of
#               face regions between Microsoft Windows Live Photo Gallery (WLPG)
#               and Metadata Working Group (MWG) formats
#
# Usage:     1) Convert from MP WLPG regions to MWG regions:
#
#               exiftool -config convert_regions.config "-regioninfo<myregion" FILE
#
#            2) Convert from MWG to WLPG regions:
#
#               exiftool -config convert_regions.config "-regioninfomp<myregionmp" FILE
#
# Requires:     ExifTool version 8.82 or later
#
# Revisions:    2012/12/27 - P. Harvey Created
#               2013/02/20 - PH Don't add ignored MP faces
#               2017/02/13 - PH Handle MP regions without Rectangle or Name entries
#
# References:   http://www.metadataworkinggroup.org/specs/
#------------------------------------------------------------------------------

%Image::ExifTool::UserDefined = (

    'Image::ExifTool::Composite' => {

        # create an MWG RegionInfo structure from a Microsoft RegionInfoMP structure
        MyRegion => {
            Require => {
                0 => 'RegionInfoMP',
                1 => 'ImageWidth',
                2 => 'ImageHeight',
            },
            ValueConv => q{
                my ($rgn, @newRgns);
                foreach $rgn (@{$val[0]{Regions}}) {
                    my $name = $$rgn{PersonDisplayName};
                    next unless $$rgn{Rectangle} or defined $name;
                    my %newRgn = ( Type => 'Face' );
                    if (defined $name) {
                        # don't add ignored faces
                        next if $name eq 'ffffffffffffffff';
                        $newRgn{Name} = $name;
                    }
                    if ($$rgn{Rectangle}) {
                        my @rect = split /\s*,\s*/, $$rgn{Rectangle};
                        $newRgn{Area} = {
                            X => $rect[0] + $rect[2]/2,
                            Y => $rect[1] + $rect[3]/2,
                            W => $rect[2],
                            H => $rect[3],
                            Unit => 'normalized',
                        } if @rect == 4;
                    }
                    push @newRgns, \%newRgn;
                }
                return {
                    AppliedToDimensions => { W => $val[1], H => $val[2], Unit => 'pixel' },
                    RegionList => \@newRgns,
                };
            },
        },

        # create a Microsoft RegionInfoMP structure from an MWG RegionInfo structure
        MyRegionMP => {
            Require => 'RegionInfo',
            ValueConv => q{
                my ($rgn, @newRgns);
                foreach $rgn (@{$val[0]{RegionList}}) {
                    next unless $$rgn{Area} or defined $$rgn{Name};
                    my %newRgn;
                    if ($$rgn{Area}) {
                        my @rect = @{$$rgn{Area}}{'X','Y','W','H'};
                        $rect[0] -= $rect[2]/2;
                        $rect[1] -= $rect[3]/2;
                        $newRgn{Rectangle} = join(', ', @rect);
                    }
                    $newRgn{PersonDisplayName} = $$rgn{Name} if defined $$rgn{Name};
                    push @newRgns, \%newRgn;
                }
                return { Regions => \@newRgns };
            },
        },
    },
);

1;  #end

The problem is that digiKam does not read the regions properly in the converted file.  I realize this is an issue with digiKam, but I believe based on other prior post, I can overcome the problem if the converted regions are written in the proper order (as a complete structure?) in the converted file.

Could anyone suggest some edits to the config file to achieve this?  I apologize that I am a Perl noob so if anyone could nudge me in the right direction, I would appreciate it.

Thank you!

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15224
    • ExifTool Home Page
Re: Tag Ordering
« Reply #1 on: February 10, 2018, 03:14:32 PM »
This config file will write the regions as proper structures.  The problem in the other thread was that the face names and coordinates were written to different structures, but that shouldn't happen if you use this config file.

Perhaps post an XMP sample that you are having problems with.

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

Bob Bourg

  • Newbie
  • *
  • Posts: 3
Re: Tag Ordering
« Reply #2 on: February 11, 2018, 09:10:06 AM »
Thanks very much for your reply.

After some more tests and looking at the xmp output, you are right that I am having a different problem.  I am attaching the xmp output from the original file and the converted file.

I am guessing that the problem stems from the fact that the original file had a face rectangle with no name assigned.  When viewing the original file in Windows Photo Gallery and hovering over the face, a rectangle is shown, but the label for it shows "Who is this?"  I assume the WPG face scan detected the face, but I never assigned a name to it. 

When viewing the converted file in digiKam, only the faces listed in the xmp file prior to the "null" face are shown.  The remaining "non-null" faces are omitted. 

I could go back in WPG and manually search for this condition and correct it, but would it be possible to modify the config file to ignore any rectangle with no assigned name?  Or even better, assign the default name "Who is this?" to such rectangles?  Again, sorry for my lack of basic Perl skills.

Bob Bourg

  • Newbie
  • *
  • Posts: 3
Re: Tag Ordering
« Reply #3 on: February 11, 2018, 10:57:21 AM »
As an update, I think I got it.  Does this mod to the config file look ok to you:

Code: [Select]
                    if (defined $name) {
                        # don't add ignored faces
                        next if $name eq 'ffffffffffffffff';
                        $newRgn{Name} = $name;
                    } else {
                        $newRgn{Name} = 'Who is this?';
                    }

digiKam worked as I wanted with this mod.

Thanks again for your help.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 15224
    • ExifTool Home Page
Re: Tag Ordering
« Reply #4 on: February 11, 2018, 12:30:38 PM »
That mod looks good.  So digiKam doesn't like a region without a name.  Good to know.

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