aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/AreaOfInterest/AOI2DScene.py70
1 files changed, 42 insertions, 28 deletions
diff --git a/src/argaze/AreaOfInterest/AOI2DScene.py b/src/argaze/AreaOfInterest/AOI2DScene.py
index 4537c8e..1faef59 100644
--- a/src/argaze/AreaOfInterest/AOI2DScene.py
+++ b/src/argaze/AreaOfInterest/AOI2DScene.py
@@ -17,39 +17,61 @@ class AOI2DScene(AOIFeatures.AOIScene):
# set dimension member
self.dimension = 2
- def look_at(self, gaze_position: GazeFeatures.GazePosition):
- """Get looked and ignored AOI names."""
+ def draw(self, frame, exclude=[], color=(0, 255, 255)):
+ """Draw AOI polygons on frame."""
+
+ for name, aoi in self.items():
+
+ if name in exclude:
+ continue
- looked = {}
- ignored = {}
+ aoi.draw(frame, color)
+ def raycast(self, gaze_position):
+ """Iterate over aoi to know which aoi is looked considering only gaze position value."""
for name, aoi in self.items():
- # TODO : use looked_region
- # looked_region, aoi_ratio, gaze_ratio = aoi2D.looked_region(gaze_position)
+ looked = aoi.looked(gaze_position)
- if aoi.looked():
+ yield name, aoi, looked
- looked[name] = aoi.look_at(gaze_position)
+ def draw_raycast(self, frame, gaze_position, exclude=[], base_color=(0, 0, 255), looked_color=(0, 255, 0)):
+ """Draw AOIs with their looked status."""
- else:
+ for name, aoi, looked in self.raycast(gaze_position):
- ignored[name] = None
+ if name in exclude:
+ continue
+
+ color = looked_color if looked else base_color
- return looked, ignored
+ if looked:
- def draw(self, frame, exclude=[], color=(0, 0, 255)):
- """Draw AOI polygons on frame."""
+ top_left_corner_pixel = numpy.rint(aoi.clockwise()[0]).astype(int)
+ cv.putText(frame, name, top_left_corner_pixel, cv.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv.LINE_AA)
+
+ # Draw form
+ aoi.draw(frame, color)
+
+ def regioncast(self, gaze_position):
+ """Iterate over areas to know which aoi is looked considering gaze position value and its accuracy."""
+ for name, aoi in self.items():
+
+ looked_region, aoi_ratio, gaze_ratio = aoi.looked_region(gaze_position)
- for name, aoi2D in self.items():
+ yield name, aoi, looked_region, aoi_ratio, gaze_ratio
+
+ def draw_regioncast(self, frame, gaze_position, exclude=[], base_color=(0, 0, 255), looked_color=(0, 255, 0)):
+ """Draw AOIs with their looked status and thei looked region."""
+
+ for name, aoi, looked_region, aoi_ratio, gaze_ratio in self.regioncast(gaze_position):
if name in exclude:
continue
- '''
- looked_region, aoi_ratio, gaze_ratio = aoi2D.looked_region(gaze_position, gaze_position.accuracy)
-
+
# Draw looked region
- looked_region.draw(frame, base_color, 4)
+ if aoi_ratio > 0:
+ looked_region.draw(frame, base_color, 4)
# TODO : Externalise this criteria
looked = aoi_ratio > 0.25 or gaze_ratio > 0.5
@@ -58,19 +80,11 @@ class AOI2DScene(AOIFeatures.AOIScene):
if looked:
- top_left_corner_pixel = numpy.rint(aoi2D.clockwise()[0]).astype(int)
+ top_left_corner_pixel = numpy.rint(aoi.clockwise()[0]).astype(int)
cv.putText(frame, name, top_left_corner_pixel, cv.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv.LINE_AA)
# Draw looked region
looked_region.draw(frame, looked_color, 4)
- # 4 corners aoi only
- if len(aoi2D) == 4:
- looked_pixel = aoi2D.looked_pixel(aoi2D.look_at(gaze_position))
- cv.circle(frame, looked_pixel, 2, color, -1)
- '''
# Draw form
- aoi2D.draw(frame, color)
-
-
-
+ aoi.draw(frame, color)