Bug 381378 - Face rectangle from XMP sidecar drawn incorrectly for EXIF rotated images
Summary: Face rectangle from XMP sidecar drawn incorrectly for EXIF rotated images
Alias: None
Product: digikam
Classification: Applications
Component: Faces-Detection (show other bugs)
Version: 5.6.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
Depends on:
Reported: 2017-06-18 20:15 UTC by Jens
Modified: 2019-12-23 15:24 UTC (History)
1 user (show)

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

example image pair with screenshot and metadata (1.24 MB, application/zip)
2017-06-18 20:15 UTC, Jens

Note You need to log in before you can comment on or make changes to this bug.
Description Jens 2017-06-18 20:15:27 UTC
Created attachment 106158 [details]
example image pair with screenshot and metadata

I have two identical JPEG photos. Both have identical XMP sidecar files specifying two faces at identical positions using mwg-rs:Regions tag (mwg-rs:Regions / rdf:Bag / rdf:li / rdf:Description / mwg-rs:Area).

The single difference between these photos is that the original image was rotated 90° left (portrait) and this was compensated by adding an EXIF orientation tag specifying 90° rotation. The other image is not rotated and has no EXIF orientation flag.

With the first image, Digikam (5.6.0-pre appimage on Mac OS X 10.12.5) will show the face rectangle specified in the XMP file at an incorrect position. The second image (normalized, and EXIF orientation flag removed or reset) is OK.

I have attached the EXIF metadata and XMP sidecars of one such image pair to test this, as well as (censored) screenshots of Digikam displaying both images with this metadata. The root cause must be in the EXIF metadata, because when I copy this XMP sidecar to other image pairs, face rectangles are displayed correctly.

Can you think of a reason why the face rectangles are not shown at the right position? How / where is the rectangle position calculated?

I have many such images  (>10'000) and I do not want to redraw or redetect all faces ...

Thank you!
Comment 1 caulier.gilles 2017-08-15 18:11:25 UTC
Git commit 9b154ceeecb732ecb97d6900ab0841e643639f4e by Gilles Caulier.
Committed on 15/08/2017 at 18:06.
Pushed by cgilles into branch 'master'.

patch from Yingjie Liu for fix face tag region if image is rotated.
The tag region in database is not expected when rotate the image. The reason : function FaceGroup::aboutToSetInfo(const ImageInfo& info) in https://cgit.kde.org/digikam.git/tree/utilities/facemanagement/facegroup.cpp#n359 invoked applyItemGeometryChanges() after transformation. Before FaceGroup::aboutToSetInfo(const ImageInfo& info), the new coordination of tag region has been written into database. However, in applyItemGeometryChanges(), the tag region coordination of tag region will be change again in database which caused a wrong coordination.
A new FaceGroup::aboutToSetInfoAfterRotate(const ImageInfo& info) is now used instead of FaceGroup::aboutToSetInfo(const ImageInfo& info) which will not invoke applyItemGeometryChanges(). Then the coordination of tag region in database is true after image transformation.
Related: bug 376681, bug 326538

M  +4    -1    NEWS
M  +2    -1    app/views/imagepreviewview.cpp
M  +11   -0    utilities/facemanagement/facegroup.cpp
M  +2    -0    utilities/facemanagement/facegroup.h

Comment 2 Jens 2017-08-15 19:10:12 UTC
THANK YOU! That was the one missing part for my "iphoto2xmp" app that was still missing. I spent countless hours browsing the SQLite db and trying to find out why rotated images almost always had incorrect face rectangle info ...

I will verify this as soon as a new appimage is ready. Thank you!
Comment 3 caulier.gilles 2017-08-15 19:22:51 UTC
Please check also other basis image transformation, as resize, flip, and crop.

Gilles Caulier
Comment 4 caulier.gilles 2019-12-23 15:24:56 UTC
Not reproducible with 7.0.0-beta1