Update micro_gestures.py
Browse files- micro_gestures.py +37 -35
micro_gestures.py
CHANGED
|
@@ -1,47 +1,49 @@
|
|
| 1 |
# micro_gestures.py
|
| 2 |
# routines for detecting single-frame micro-gestures
|
| 3 |
|
| 4 |
-
from utils import
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
return (
|
| 13 |
-
is_finger_extended(landmarks, finger="thumb", direction="up") and
|
| 14 |
-
not is_finger_extended(landmarks, finger="index") and
|
| 15 |
-
not is_finger_extended(landmarks, finger="middle") and
|
| 16 |
-
not is_finger_extended(landmarks, finger="ring") and
|
| 17 |
-
not is_finger_extended(landmarks, finger="pinky")
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
def thumb_down(landmarks):
|
| 21 |
-
"""thumb extended downward, others curled."""
|
| 22 |
-
return (
|
| 23 |
-
is_finger_extended(landmarks, finger="thumb", direction="down") and
|
| 24 |
-
all(not is_finger_extended(landmarks, finger=f) for f in ["index", "middle", "ring", "pinky"])
|
| 25 |
-
)
|
| 26 |
|
| 27 |
def index_pointing_up(landmarks):
|
| 28 |
-
|
| 29 |
-
return (
|
| 30 |
-
is_finger_extended(landmarks, finger="index", direction="up") and
|
| 31 |
-
all(not is_finger_extended(landmarks, finger=f) for f in ["middle", "ring", "pinky", "thumb"])
|
| 32 |
-
)
|
| 33 |
|
| 34 |
-
def
|
| 35 |
-
|
| 36 |
-
return all(not is_finger_extended(landmarks,
|
| 37 |
|
| 38 |
-
def
|
| 39 |
-
|
| 40 |
-
return all(is_finger_extended(landmarks,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def ok_sign(landmarks):
|
| 43 |
-
|
| 44 |
thumb_tip = landmarks[4]
|
| 45 |
index_tip = landmarks[8]
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# micro_gestures.py
|
| 2 |
# routines for detecting single-frame micro-gestures
|
| 3 |
|
| 4 |
+
from utils import distance_between_points, is_finger_extended
|
| 5 |
|
| 6 |
+
def fist_closed(landmarks):
|
| 7 |
+
# all fingers curled into palm
|
| 8 |
+
return all(not is_finger_extended(landmarks, finger=f) for f in ["thumb","index","middle","ring","pinky"])
|
| 9 |
+
|
| 10 |
+
def palm_open(landmarks):
|
| 11 |
+
# all fingers extended
|
| 12 |
+
return all(is_finger_extended(landmarks, finger=f) for f in ["thumb","index","middle","ring","pinky"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def index_pointing_up(landmarks):
|
| 15 |
+
# only index extended up
|
| 16 |
+
return is_finger_extended(landmarks, "index", "up") and all(not is_finger_extended(landmarks,f) for f in ["thumb","middle","ring","pinky"])
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
def v_sign(landmarks):
|
| 19 |
+
# index and middle extended, others curled
|
| 20 |
+
return is_finger_extended(landmarks, "index") and is_finger_extended(landmarks, "middle") and all(not is_finger_extended(landmarks,f) for f in ["thumb","ring","pinky"])
|
| 21 |
|
| 22 |
+
def thumb_up(landmarks):
|
| 23 |
+
# thumb up, others curled
|
| 24 |
+
return is_finger_extended(landmarks,"thumb","up") and all(not is_finger_extended(landmarks,f) for f in ["index","middle","ring","pinky"])
|
| 25 |
+
|
| 26 |
+
def thumb_side(landmarks):
|
| 27 |
+
# thumb horizontal, others curled
|
| 28 |
+
return is_finger_extended(landmarks,"thumb") and all(not is_finger_extended(landmarks,f) for f in ["index","middle","ring","pinky"])
|
| 29 |
+
|
| 30 |
+
def pinky_up(landmarks):
|
| 31 |
+
# only pinky extended up
|
| 32 |
+
return is_finger_extended(landmarks,"pinky","up") and all(not is_finger_extended(landmarks,f) for f in ["thumb","index","middle","ring"])
|
| 33 |
+
|
| 34 |
+
def four_fingers(landmarks):
|
| 35 |
+
# four fingers extended, thumb curled
|
| 36 |
+
return all(is_finger_extended(landmarks,f) for f in ["index","middle","ring","pinky"]) and not is_finger_extended(landmarks,"thumb")
|
| 37 |
|
| 38 |
def ok_sign(landmarks):
|
| 39 |
+
# thumb and index touching, others extended
|
| 40 |
thumb_tip = landmarks[4]
|
| 41 |
index_tip = landmarks[8]
|
| 42 |
+
return distance_between_points(thumb_tip,index_tip) < 0.05 and all(is_finger_extended(landmarks,f) for f in ["middle","ring","pinky"])
|
| 43 |
+
|
| 44 |
+
def palm_inward(landmarks):
|
| 45 |
+
# palm facing body (approximate using wrist-middle_finger vector)
|
| 46 |
+
wrist = landmarks[0]
|
| 47 |
+
mcp = landmarks[9]
|
| 48 |
+
vector_y = mcp[1] - wrist[1]
|
| 49 |
+
return vector_y > 0 # palm facing down or inward
|