Bug 416744 - Changes are not saved after deleting face rectangle from picture
Summary: Changes are not saved after deleting face rectangle from picture
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Faces-Workflow (show other bugs)
Version: 7.2.0
Platform: unspecified All
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-25 12:42 UTC by MarcP
Modified: 2021-11-11 21:15 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 7.4.0
Sentry Crash Report:


Attachments
group-of-people-clapping-X6D3M1.jpg (189.01 KB, image/jpeg)
2020-01-27 19:26 UTC, MarcP
Details

Note You need to log in before you can comment on or make changes to this bug.
Description MarcP 2020-01-25 12:42:42 UTC
SUMMARY

This only applies to some pictures. I have not figured out the pattern yet.

When you add a face rectangle to a picture, these changes are saved into the picture (and digikam's database). However, when you delete a face rectangle, changes are not saved. You can check that by re-reading the metadata from file, and the deleted face rectangles will appear again.

STEPS TO REPRODUCE
1. Delete a face rectangle from a picture.
2. (wait a couple of seconds)
3. Item / Re-read metadata from file.

OBSERVED RESULT
- The deleted faces appear again.

EXPECTED RESULT
- Deleted faces should have been deleted from the picture.

SOFTWARE/OS VERSIONS
digikam-7.0.0-beta2-20200124T055125-x86-64.appimage in Ubuntu 18.04LTS with Unity.
Comment 1 Maik Qualmann 2020-01-27 07:49:56 UTC
Marc, this problem cannot be reproduced here. Not even with my slower network share. The writing process may not have been completed before you reread the metadata again. Without a test image with which the problem can be reproduced and the output from the console, we cannot do anything here. Technically, we delete all facial rectangles in the metadata before we write new ones.

Maik
Comment 2 caulier.gilles 2020-01-27 08:04:14 UTC
I just tested here to try to reproduce the problem with my NAS, and i cannot as Maik said...

Gilles Caulier
Comment 3 MarcP 2020-01-27 08:05:48 UTC
That is weird, but I can't tell for sure what is causing it. Yesterday I was correcting many duplicated faces (since the bug about the mispositioned faces was solved, but I had already rescanned those pictures for faces...), so basically I had to delete existing faces from images. I actually tried in two different computers, with the same result (using the last beta2 available in both).

Basically, from the People panel, I select a person to see his/her faces. When you add, rename, or reposition a face in a picture, changes get saved immediately (I can see the progress bar at the bottom). However, if you just delete a face from a picture (preview view), changes are not saved. You have to manually write metadata to the file. (If you add or rename a face after deleting another one, then the metadata gets saved just fine).

It's not always consistent, since I remember this didn't happen in the past. But it's there >90% of the time. Maybe it only happens if the picture has been opened from the people panel? I don't think it depends on the particular picture either.

Anyway, I will try to narrow it down later today when I'm at home. I'll attach a sample picture so you can test it too
Comment 4 Maik Qualmann 2020-01-27 09:56:23 UTC
You write that when you delete a face, the metadata is not saved and you have to do it manually. This is not correct, even when deleting a face in preview mode, the metadata is saved immediately. I currently have the Windows version here and it works as expected there too, I can reread immediately, but the face does not come back.

Maik
Comment 5 MarcP 2020-01-27 19:26:55 UTC
Created attachment 125467 [details]
group-of-people-clapping-X6D3M1.jpg
Comment 6 MarcP 2020-01-27 19:30:39 UTC
Ok, I finally found out what was happening, because sometimes when deleting faces changes were saved, and other weren't.

It turns out the problem only arises when there is a duplicated face rectangle in a picture. 

In my case, I was deleting duplicated face rectangles that appeared as a consequence of re-scanning the images when Bug 372340 was present, so everyone had two face rectangles, a "landscape" one, and a "portrait" one (because of the incorrect rotation of the picture), where one of them was usually pointing at the sky or another background element.

Let' say there are two Person 1 and one Person 2 rectangles in an image (use attached file as an example). If you delete the face of Person 2, changes will be written (Item/re-read metadata, just to confirm this). If you delete a face of Person 1 (any of them), changes will NOT be written (if you re-read the metadata, the face will reappear).

Having the same person twice or more times in a pictures is not common, but it can happen. For instance, someone looking himself at the mirror, or a photo with a framed picture of that person in the background.


I captured the whole thing in video:
https://imgur.com/a/W6nIo5r
Comment 7 Maik Qualmann 2020-01-27 22:07:04 UTC
Interesting problem ((:-))
Since the tag still exists a second time on the image and is a confirmed face, it is not removed from the image and therefore no metadata is written because there have been no changes to the tags...

Maik
Comment 8 spam-receiver 2021-06-02 15:40:14 UTC
I would like to confirm that the issue is still present in 7.2.0.

I can confirm that changes will not be written if the photo has *two* face rectangles of the same person, and *one* of the rectangles is removed.

Even worse:

I tried to force metadata update by moving the *second* rectangle by a few pixels.
Metadata has been written to the file as I was able to observe in the progrss bar.
After completion of the write process, I triggered re-reading of the metadata:
The removed face rectangle was back again!

:-(
Comment 9 caulier.gilles 2021-06-02 16:41:21 UTC
What's about to use 7.3.0 pre-release available here:

https://files.kde.org/digikam/

Problem still reproducible ?

Gilles Caulier
Comment 10 spam-receiver 2021-06-02 16:43:44 UTC
(In reply to caulier.gilles from comment #9)
> What's about to use 7.3.0 pre-release available here:
> 
> https://files.kde.org/digikam/
> 
> Problem still reproducible ?
> 
> Gilles Caulier

Well, I would need a second computer to install 7.3.0, wouldn't I?
Comment 11 Maik Qualmann 2021-06-02 16:50:45 UTC
The problem still exists as it is very rare and I want to fix it "cleanly" without a hack. I'll check it out again soon.

Maik
Comment 12 caulier.gilles 2021-06-02 16:55:23 UTC
No need a second computer. Use AppImage Linux bundle which include all in place in memory and do not install file on your computer. Just get the appimage version, change file as executable, and run it.
Comment 13 spam-receiver 2021-06-02 21:08:47 UTC
(In reply to caulier.gilles from comment #12)
> No need a second computer. Use AppImage Linux bundle which include all in
> place in memory and do not install file on your computer. Just get the
> appimage version, change file as executable, and run it.

I was quite cumbersome, but finally I managed to run the appimage in the Windows/Linux subsystem...
* installation of the Linux subsystem, installation of Ubuntu within the subsystem
* installation of an X server on Windows, configuring it
* extracting the appimage because it can't be mounted
* installing a bunch of libraries
* and some more tweaking
The rendering will not be optimal with this setup, e.g. the face labels and edit buttons will not be visible on the preview, and only parts of the face rectangle. The tooltips of the confirm and remove buttons will be shown, this helped me locating them...

Alright, back to topic:

It seems better now but not completely solved: 

I have some test photos. On those, the same faces are tagged twice because I used different programs originally (WLPG and Picasa).

When I remove one of the rectangles with digikam, it will be removed from the database but not from the file. The removed rectangle will re-appear when I reload the metadata.

When I remove one of the rectangles and modify the other (move by a few pixels), the removed one will not re-appear after reloading of metadata.

I've checked this with exiftool:

Original file and file after removing one face rectangle will prduce the same output:
> exiftool test1.JPG | grep -i region
Region Name                     : Name A, Name A, Name B, Name B
Region Type                     : Face, Face, Face, Face
Region Area X                   : 0.54475, 0.5435, 0.433375, 0.4345
Region Area Y                   : 0.4145, 0.431667, 0.283333, 0.297
Region Area W                   : 0.1095, 0.0575, 0.11425, 0.0645
Region Area H                   : 0.174333, 0.0766667, 0.183333, 0.086

After moving one other rectangle a bit:
> exiftool test1.JPG | grep -i region
Region Name                     : Name A, Name A, Name B
Region Type                     : Face, Face, Face
Region Area X                   : 0.5435, 0.54475, 0.432625
Region Area Y                   : 0.431667, 0.4145, 0.288
Region Area W                   : 0.0575, 0.1095, 0.11425
Region Area H                   : 0.0766667, 0.174333, 0.183333
Comment 14 spam-receiver 2021-07-11 14:25:45 UTC
I removed the "AppImage Linux" platform tag because I obseved the issue on Windows.
I used the AppImage only to check whether the issue was still present in a development build.
Comment 15 Maik Qualmann 2021-07-11 16:01:37 UTC
Git commit 0bbcbe94f5e67c34290486f03c9d66c75072928e by Maik Qualmann.
Committed on 11/07/2021 at 16:00.
Pushed by mqualmann into branch 'master'.

add workaround to write metadata if duplicate face tags are removed
FIXED-IN: 7.4.0

M  +2    -1    NEWS
M  +10   -3    core/libs/database/tags/facetagseditor.cpp

https://invent.kde.org/graphics/digikam/commit/0bbcbe94f5e67c34290486f03c9d66c75072928e
Comment 16 spam-receiver 2021-11-11 21:15:29 UTC
This is scheduled for 7.4.0. When will the release be available?