aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéo de la Hogue2022-05-04 16:06:34 +0200
committerThéo de la Hogue2022-05-04 16:06:34 +0200
commita10928dc929718873e6ee0e508bce051a19bd86a (patch)
tree5e401efcd1dceaafcb7cec14dc326c993bf76570 /src
parent5426868bbee3940a479cd0d7a1f8cc1d7642c8a1 (diff)
downloadargaze-a10928dc929718873e6ee0e508bce051a19bd86a.zip
argaze-a10928dc929718873e6ee0e508bce051a19bd86a.tar.gz
argaze-a10928dc929718873e6ee0e508bce051a19bd86a.tar.bz2
argaze-a10928dc929718873e6ee0e508bce051a19bd86a.tar.xz
Adding looked_pixel function and making look_at function based on non orthogonal projection.
Diffstat (limited to 'src')
-rw-r--r--src/argaze/AreaOfInterest/AOIFeatures.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/argaze/AreaOfInterest/AOIFeatures.py b/src/argaze/AreaOfInterest/AOIFeatures.py
index dc38eb8..001affa 100644
--- a/src/argaze/AreaOfInterest/AOIFeatures.py
+++ b/src/argaze/AreaOfInterest/AOIFeatures.py
@@ -41,20 +41,39 @@ class AreaOfInterest(numpy.ndarray):
return mpath.Path(self).contains_points([gaze_position])[0]
def look_at(self, gaze_position):
- """Get where the area is looked."""
+ """Get where the area is looked using non orthogonal projection."""
if self.dimension() != 2:
raise RuntimeError(f'Bad area dimension ({self.dimension()})')
- P = numpy.array(gaze_position)
+ clockwise_area = self.clockwise()
+
+ O = clockwise_area[0] # Origin
+ G = numpy.array(gaze_position) - O # Gaze point
+
+ M = numpy.array([clockwise_area[1] - O, clockwise_area[-1] - O]) # Basis projection matrix M = {U | V}
+ Mt = numpy.transpose(M)
+
+ Gp = numpy.dot(numpy.dot(numpy.linalg.inv(numpy.dot(Mt, M)), Mt), G)# Projected gaze point
+
+ return numpy.around(Gp, 4).tolist()
+
+ def looked_pixel(self, look_at):
+ """Get which pixel is looked."""
+
+ if self.dimension() != 2:
+ raise RuntimeError(f'Bad area dimension ({self.dimension()})')
clockwise_area = self.clockwise()
- O = clockwise_area[0]
- OX, OY = clockwise_area[1] - O, clockwise_area[-1] - O
- OP = P - O
+ O = clockwise_area[0] # Origin
+ Gp = numpy.array(look_at) # Projected gaze point
+ M = numpy.array([clockwise_area[1] - O, clockwise_area[-1] - O]) # Basis projection matrix M = {U | V}
+ Mt = numpy.transpose(M)
+
+ Lp = O + numpy.dot(M, Gp) # Projected gaze pixel
- return ( round(numpy.dot(OP, OX) / numpy.dot(OX, OX), 3), round(numpy.dot(OP, OY) / numpy.dot(OY, OY), 3))
+ return numpy.rint(Lp).astype(int).tolist()
def draw(self, frame, color):