diff options
-rw-r--r-- | src/argaze/AreaOfInterest/AOIFeatures.py | 31 |
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): |