Module src.recognition.persistence
Classes
class Persistence (n: int = 20, threshold: float = 0.8)-
Persistence - checking for persistence in a queue of gestures.
The idea is to have a FIFO-queue of the last n frames gestures for each hand. Whenever the last element in that queue changes we check the if the ratio between frames containing and not containing that gesture reaches a certain threshold. If it does, we can safely say the person intended to do that gesture.
Args
n- Size of first half of queue for gesture intention second half for zoom smoothing
threshold- Minimum ratio ([0.0, 1.0]) for regarding the current gesture as intentional.
Methods
def add(self, gesture: str) ‑> NoneType-
Adds the provided gesture to, and removes the first in the queue.
Args
gesture- Gesture string to be added to the queue. Accepts
None, which is regarded as no gesture.
def check_intent(self, gesture: str) ‑> bool-
Checks if the provided gesture passes the threshold.
Args
gesture- Gesture to check against the queue.
Returns
True if the provided gesture make up more than self._threshold of the internal queue.
def check_ratio(self, gesture: str) ‑> float-
Check the ratio of the provided gesture in the queue.
If the queue is ["G1", "G1", "G2", "G3"], calling check_ratio("G1") will return 2 / 4 = 0.5
Args
gesture- The intended gesture to check the ratio for.
Returns
The ratio of the provided gesture in the current queue.