Fixed face region orientation
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
""" version info """
|
""" version info """
|
||||||
|
|
||||||
__version__ = "0.39.22"
|
__version__ = "0.39.23"
|
||||||
|
|||||||
@@ -235,8 +235,8 @@ class FaceInfo:
|
|||||||
Reference:
|
Reference:
|
||||||
https://photo.stackexchange.com/questions/106410/how-does-xmp-define-the-face-region
|
https://photo.stackexchange.com/questions/106410/how-does-xmp-define-the-face-region
|
||||||
"""
|
"""
|
||||||
x = self.center_x
|
x, y = self.center_x, self.center_y
|
||||||
y = 1.0 - self.center_y
|
x, y = self._fix_orientation((x, y))
|
||||||
h = self.size_pixels / self.photo.height
|
h = self.size_pixels / self.photo.height
|
||||||
w = self.size_pixels / self.photo.width
|
w = self.size_pixels / self.photo.width
|
||||||
|
|
||||||
@@ -256,8 +256,10 @@ class FaceInfo:
|
|||||||
Reference:
|
Reference:
|
||||||
https://docs.microsoft.com/en-us/windows/win32/wic/-wic-people-tagging
|
https://docs.microsoft.com/en-us/windows/win32/wic/-wic-people-tagging
|
||||||
"""
|
"""
|
||||||
x = self.center_x - self.size_pixels / self.photo.width / 2
|
x, y = self.center_x, self.center_y
|
||||||
y = 1.0 - self.center_y - self.size_pixels / self.photo.height / 2
|
x, y = self._fix_orientation((x, y))
|
||||||
|
x = x - self.size_pixels / self.photo.width / 2
|
||||||
|
y = y - self.size_pixels / self.photo.height / 2
|
||||||
|
|
||||||
# though the docs clearly say height, width, these appear to be flipped
|
# though the docs clearly say height, width, these appear to be flipped
|
||||||
h = self.size_pixels / self.photo.width
|
h = self.size_pixels / self.photo.width
|
||||||
@@ -308,6 +310,33 @@ class FaceInfo:
|
|||||||
_, _, yaw = self.roll_pitch_yaw()
|
_, _, yaw = self.roll_pitch_yaw()
|
||||||
return yaw
|
return yaw
|
||||||
|
|
||||||
|
def _fix_orientation(self, xy):
|
||||||
|
""" Translate an (x, y) tuple based on image orientation
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
xy: tuple of (x, y) coordinates for point to translate
|
||||||
|
in format used by Photos (percent of height/width)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
(x, y) tuple of translated coordinates
|
||||||
|
"""
|
||||||
|
# Reference: https://github.com/neilpa/phace/blob/7594776480505d0c389688a42099c94ac5d34f3f/cmd/phace/draw.go#L79-L94
|
||||||
|
|
||||||
|
orientation = self.photo.orientation
|
||||||
|
x, y = xy
|
||||||
|
if orientation in [1, 2]:
|
||||||
|
y = 1.0 - y
|
||||||
|
elif orientation in [3, 4]:
|
||||||
|
x = 1.0 - x
|
||||||
|
elif orientation in [5, 6]:
|
||||||
|
x, y = 1.0 - y, 1.0 - x
|
||||||
|
elif orientation in [7, 8]:
|
||||||
|
x, y = y, x
|
||||||
|
else:
|
||||||
|
logging.warning(f"Unhandled orientation: {orientation}")
|
||||||
|
|
||||||
|
return (x, y)
|
||||||
|
|
||||||
def _make_point(self, xy):
|
def _make_point(self, xy):
|
||||||
""" Translate an (x, y) tuple based on image orientation
|
""" Translate an (x, y) tuple based on image orientation
|
||||||
and convert to image coordinates
|
and convert to image coordinates
|
||||||
@@ -322,22 +351,11 @@ class FaceInfo:
|
|||||||
# Reference: https://github.com/neilpa/phace/blob/7594776480505d0c389688a42099c94ac5d34f3f/cmd/phace/draw.go#L79-L94
|
# Reference: https://github.com/neilpa/phace/blob/7594776480505d0c389688a42099c94ac5d34f3f/cmd/phace/draw.go#L79-L94
|
||||||
|
|
||||||
orientation = self.photo.orientation
|
orientation = self.photo.orientation
|
||||||
x, y = xy
|
x, y = self._fix_orientation(xy)
|
||||||
dx = self.photo.width
|
dx = self.photo.width
|
||||||
dy = self.photo.height
|
dy = self.photo.height
|
||||||
if orientation in [1, 2]:
|
if orientation in [5, 6, 7, 8]:
|
||||||
y = 1.0 - y
|
|
||||||
elif orientation in [3, 4]:
|
|
||||||
x = 1.0 - x
|
|
||||||
elif orientation in [5, 6]:
|
|
||||||
x, y = 1.0 - y, 1.0 - x
|
|
||||||
dx, dy = dy, dx
|
dx, dy = dy, dx
|
||||||
elif orientation in [7, 8]:
|
|
||||||
x, y = y, x
|
|
||||||
dx, dy = dy, dx
|
|
||||||
else:
|
|
||||||
logging.warning(f"Unhandled orientation: {orientation}")
|
|
||||||
|
|
||||||
return (int(x * dx), int(y * dy))
|
return (int(x * dx), int(y * dy))
|
||||||
|
|
||||||
def _make_point_with_rotation(self, xy):
|
def _make_point_with_rotation(self, xy):
|
||||||
|
|||||||
Reference in New Issue
Block a user