From a10928dc929718873e6ee0e508bce051a19bd86a Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 4 May 2022 16:06:34 +0200 Subject: Adding looked_pixel function and making look_at function based on non orthogonal projection. --- src/argaze/AreaOfInterest/AOIFeatures.py | 31 +++++++++++++++++++++++++------ 1 file 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): -- cgit v1.1