Suggested Update to PhotoTaggingGramplet to Support XMP Face Regions

I manage all my image metadata and face tags in DigiKam and then add the photos to Gramps. Currently, Gramps doesn’t read the XMP Face regions embedded in the image files. I use the Windows AIO and therefore can’t use face detection. So I have been left to manually redraw the regions and tag people.

I found this support topic - 0007442: [PhotoTagging] Read face metadata created by Digikam (KDE) from image (jpg) XMP metadata and autolink to persons - Gramps - Bugtracker – Free Genealogy Software and I’ve been expanding on some programming that was in the discussion. The code in the discussion was never added to the Gramplet. While the ticket requests reading XMP Face tags and Autolinking to persons, I am focusing only on reading the Face Tags. I am not endeavoring to Auto-link.

Currently,

  • I have integrated the code into the Gramps5.1 PhotoTaggingGramplet. (Add support XMP-mwg-rs regions in PhotoTaggingGramplet · gramps-project/addons-source@eb04653 · GitHub)
  • The XMP Regions will be visible if there are no regions already defined in Gramps for an image. If a user has already tagged an image manually, the XMP Regions are not displayed so as not to confuse the user.
  • I have added a new column that shows the “XMP Region Name” defined in the image file.
  • I have made the columns (Person, Age, XMP Region Name) resizable and allow the order to be changed. I think this makes comparing the ‘XMP Region Name’ to the Person easier.
  • I have only tested in on Gramps 5.1.3 / Windows 10 AIO.

This a screen capture of the interface when an image with XMP Regions is loaded and has not yet been tagged in Gramps.

I am hoping this may be useful to other users and I am looking for guidance on how to proceed with contributing to the Gramplet. I have read the developing addons section of the wiki and it seems focused on new add-ons rather than contributing to existing addons.

Thanks for any guidance you can provide.
Bruce.

5 Likes

Do you know if the Digicam regions are supported more widely? Do other programs generate these as well?

This seems like a great idea, especially if more programs will support this in the future. Please make this into a PR, so we can get it integrated to the addon for everyone’s use.

There’s a mention of XMP data in the Edit Image Exif Metadata Gramplet. Perhaps it could be adapted?

I’ve never used that or the Image Metadata Gramplet. (The GExiv2 for Image metadata prerequisite documentation was fairly convoluted.)

Interesting.

We could also add the XMP file (which is a standard format for photo management tools - ligthroom, darktable and others) that DigiKam generates among the gramps media. This xmp media could be associated with a source and a citation (eg Automatic recognition on a given date of the faces on the photo representing xxxxx, validated by xyz). The citation would then be applied to the photo media from which the clipping of individuals comes out while transporting it with the media of this source.

  • It would allow to have a more standardized “photo” file (xmp) than the gramps xml file associated with this photo media.
  • It would fill the gedcom gap which does not convey (I’m not sure) the notion of coordinates of people (or signatures) on the image. There they would be included through the source represented by the xmp file.
1 Like

Yes. The regions are part of a larger metadata standard and are not proprietary or unique to DigiKam. Other programs do support this. Lightroom, Darktable, I believe Piscasa did. The tags are read by tools like exiftool and Exiv2.

I had not considered that the data may be in a sidecar XMP file. That’s a good point. I will look into it reading the data from a sidecar file, if it exists.

On your other idea, you are way ahead of me in understanding Gramps and how everything relates.

I’ve just reviewed the GExiv2 documentation and run a quick test and Gexiv2 doesn’t appear to support reading XMP data from sidecar files, only data embedded directly in the image. So I have gone ahead with the PR#478 (Add support for XMP-mwg-rs Regions in Image Files - Maintenance/gramps51 by brucejackson · Pull Request #478 · gramps-project/addons-source · GitHub)

1 Like

I’m building a sample Tree for a tutorial article that will include Photo Tagging.
It is still fairly primitive.
The Photo Tagging keeps throwing errors when Selecting a new person for a rectangle.

Can I send a copy of the .gpkg for your experiments? (I’d like to be able to beta test as well.)

An equivalent .webp formatted image (which Gimp claims to include XMP and a thumbnail) is ~400kb. That new format is not compatible with the Photo Tagging. The .jpg is a similar size while the .png is about 2.4MB.

Yes, you can send the gpkg. What is the error you are getting? Which version of the photo tagging gramplet are you using?

Is a mantis issue needed to update Gramps to support webp?

The .gpkg has been sent via PM. (Note that I am still cleaning the GEDCOM data. Still have 120 of more than 800 Places to fit into a Place hierarchy is GPS coordinates. And the QUAY values in the Brother’s Keeper GEDCOM did not properly apply as Confidence levels. The ugliest cleanup is that the Citation page numbers are saved as Attributes of the GEDCOM and they have to be moved to the source reference book.)

It is probably related to the Face Detection Python libraries not liking Windoze

After I create a rectangle, I choose the “Select” context menu for the new row. When the PhotoTagger receives Person from the Select Person dialog, the error appears:

2776264: ERROR: grampsapp.py: line 174: Unhandled exception
Traceback (most recent call last):
  File "C:\Users\DistrictSupport\AppData\Roaming\gramps\gramps51\plugins\PhotoTaggingGramplet\PhotoTaggingGramplet.py", line 847, in sel_person_clicked
    self.refresh()
  File "C:\Users\DistrictSupport\AppData\Roaming\gramps\gramps51\plugins\PhotoTaggingGramplet\PhotoTaggingGramplet.py", line 516, in refresh
    self.refresh_list()
  File "C:\Users\DistrictSupport\AppData\Roaming\gramps\gramps51\plugins\PhotoTaggingGramplet\PhotoTaggingGramplet.py", line 1053, in refresh_list
    xmp_name = region.xmp_person
AttributeError: 'Region' object has no attribute 'xmp_person'

The Gramplet does not show the person. But after exiting Gramps and reloading, the new definition is apparently good.

I can reproduce the issue on my own tree, so unless there is something specific you need me to look at in the gramps file you sent I think I need it.

I have set up a new development environment to correct this and test that nothing else breaks, but so far it looks like Line 1041 in PhotoTaggingGramplet.py needs to be:

xmp_name = ""

instead of

xmp_name = region.xmp_region

Thanks for reporting this.

1 Like

It is a reasonably sized experimental tree. There are a couple thousand people in the Tree. So matching the selection to a Person to a rectangle has an real-world pain level. (All the 45 People in the target image have a custom ID starting with “POTUS” (President of the US) and a dated “Elected” Event so you can try filters and sorts. That helps determine if workflows can be streamlined.

  • The image file (a collage poster) is very difficult to set appropriate rectangle sizes. The archive includes a .webp and .jpg of the same image.
  • It demonstrates that an option to re-order the Rectangles would be helpful
  • Targeting an Event or Place for whole image would be useful
  • I tried to tag a scan of a handwritten document. I was hoping to use the tags to indicate where an Object is referenced. (For instance, a rectangle on a foreign language Will for a mention of a (Child & their spouse) to their Family object and a Note containing the inventory of heirlooms.) But only People may be linked.
  • in the (admittedly damaged) linking feature of Notes, if the Person view is active, you can change your Active Person, then highlighting that name in the Note & linking causes it to pre-populate with the Active Person. It there an easier way than using the Person Selector for the Rectangle? Drag’n’drop DOES work from the People view and the PhotoTagging gramplet undocked.

OK… so I just set 45 rectangles and associated them with Persons.

I tried the People Selector, dragging from the Person View, and dragging from the Clipboard.

The automatic pop-up after drawing the rectangle (with all those “Replace to ” menu items) quickly began interfering with the workflow. You’ve already have a toolbar and 2 more gadgets (a switch for Double-click action - between Edit/MakeActive; and; a pop-up list for the Replace) could eliminate the need for the pop-up.

Assigning via the People selectors was the most painful. Detaching the Photo Tagging Gramplet and using the People view as a “pallette of drag’n’drop People” was better but required dragging across too much screen real-estate. From the clipboard was easiest to arrange the “pallette” near the drop target zones.

Drawing a new rectangle forces a re-draw of the list. That works OK until the list needs a vertical scrollbar. Then the user is CONSTANTLY messing with the scrollbar. Works better if you reverse the 1st column to change row order from low-to-high to high-to-low. That ensures the new Rectangle’s row is always accessible at the top.

Single click to change rectangles would be better if it centered the list on the row associated with the rectangle.

I’ve taken a look at the images and noticed that neither image has embedded face metadata, so the images don’t work at all with the addition I am proposing to the PhotoTagging Gramplet.

When I first saw the PhotoTagging Gramplet, I tried drawing regions. I didn’t like the experience. I also prefer to manage the metadata for the images using Digikam. Digikam allows me to embed the metadata in the image file. This makes the information shareable between apps and people. Because of how I approach it, I can’t really help with the workflow of drawing selection areas. I have very little experience with it - what experience I had was about 2 years ago.

That said here is how I would tackle this image:

  • ensure the Digikam metadata setting write Face Tags is enabled

  • add the image to a Digikam album

  • right mouse click on the image and select scan for faces

  • once that is done, right-mouse click and select show faces.

  • At this point, I might need to manually draw some regions.

  • I type in the names of the people. (in this example, I just tagged 3 Presidents)

  • Once I am done with all my metadata editing, I add the image to Gramps.

  • In the proposed PhotoTagging Gramplet I will see something like this. You will notice the Face Regions I created and saved in Digikam.

  • Rather than interacting with the rectangles, I right-mouse click the listing on the right and chose Select

  • Then I search for the appropriate person in Gramps.

1 Like

When I want to do this, I add the image to the Gallery for the Event or Place.

1 Like

I have never played with this feature.

I did not know that. Thanks.

1 Like

An invalid Rectangle breaks Import and Export. This failure cripples restoring a backup .gpkg file. It creates unusable backups without any alerts.

See

The failure was traced back to a corrupted handle for a objref the <people></people> XML chunk. The block was for a tagging rectangle in an image Media object. That was from the Photo Tagging gramplet.
Oddly, there were TWO separate objref tags (covering different region coordinates) for the Person object. The first had a valid handle, the 2nd had a NULL handle with ONLY an underscore.

      <objref hlink="_">
       <region corner1_x="87" corner1_y="66" corner2_x="99" corner2_y="75"/>
      </objref>