hand-guest-control 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,6 @@
1
1
  # hand-guest-control
2
2
 
3
- Hand gesture detection and state management using MediaPipe landmarks. Extracted from `mn-hand-control`.
4
-
5
- ## Demo UI (test package in browser)
6
-
7
- ```bash
8
- cd npm/hand-guest-control
9
- npm install
10
- npm run demo
11
- ```
12
-
13
- Open **http://localhost:5180** — webcam + live hand state overlay.
3
+ Hand gesture detection and action mapping from MediaPipe landmarks. TypeScript types included.
14
4
 
15
5
  ## Install
16
6
 
@@ -18,70 +8,54 @@ Open **http://localhost:5180** — webcam + live hand state overlay.
18
8
  npm install hand-guest-control @mediapipe/tasks-vision
19
9
  ```
20
10
 
21
- Or local workspace link during development:
22
-
23
- ```bash
24
- npm install ../npm/hand-guest-control
25
- ```
26
-
27
11
  ## Usage
28
12
 
29
- ### Core — gesture state machine
30
-
31
- ```javascript
32
- import { HandStateManager, HAND_STATES } from 'hand-guest-control';
13
+ ```typescript
14
+ import { HandStateManager, HAND_STATES, GESTURE_ACTIONS } from 'hand-guest-control';
15
+ import { createHandLandmarker } from 'hand-guest-control/mediapipe';
33
16
 
34
17
  const manager = new HandStateManager({
35
- rotationSensitivity: 4,
36
18
  waitingTimeout: 10000,
37
19
  startingDelay: 3000,
38
- debug: false
20
+ swipeSource: 'index' // 'index' | 'wrist'
39
21
  });
40
22
 
41
- // landmarks from MediaPipe HandLandmarker
42
- const { state, rotation } = manager.processLandmarks(landmarks);
43
-
44
- if (state === HAND_STATES.OPEN) {
45
- // zoom in
46
- }
47
-
48
- if (state === HAND_STATES.SWIPE_NEXT) {
49
- // next item
50
- }
23
+ const landmarker = await createHandLandmarker();
24
+ const results = await landmarker.detectForVideo(videoCanvas, Date.now());
25
+ const { state, primaryAction, actions, rotation, palmDirection } =
26
+ manager.processLandmarks(results.landmarks?.[0]);
51
27
  ```
52
28
 
53
- ### MediaPipe helper
29
+ ## Default actions
30
+
31
+ | Gesture | Action |
32
+ |---------|--------|
33
+ | Swipe left / right | `swipe_left` / `swipe_right` |
34
+ | Open palm / closed fist | `zoom_out` / `zoom_in` |
35
+ | Palm left / right / up / down | `rotate_left` / `rotate_right` / `rotate_up` / `rotate_down` |
36
+ | Thumb up | `ok` |
37
+
38
+ Override via `actionMap`. Set `mapActions: false` to get states only.
39
+
40
+ ## Config
41
+
42
+ ```typescript
43
+ new HandStateManager({
44
+ swipeSource: 'index',
45
+ swipeMinRange: 0.03,
46
+ swipeCooldownMs: 2000,
47
+ palmDirectionThreshold: 0.025,
48
+ rotationActionThreshold: 0.5,
49
+ enableContinuousRotation: true,
50
+ mapActions: true,
51
+ actionMap: { /* partial override */ }
52
+ });
53
+ ```
54
54
 
55
- ```javascript
56
- import { createHandLandmarker } from 'hand-guest-control/mediapipe';
55
+ Invalid config throws `ConfigValidationError`.
57
56
 
58
- const landmarker = await createHandLandmarker({
59
- minHandDetectionConfidence: 0.6
60
- });
57
+ ## Exports
61
58
 
62
- const results = await landmarker.detectForVideo(videoElement, Date.now());
63
- const { state, rotation } = manager.processLandmarks(results.landmarks?.[0]);
64
- ```
59
+ `HandStateManager`, `HandGestureDetector`, `ActionMapper`, `mapGestureToAction`, `validateHandConfig`, `mergeHandConfig`, `HAND_STATES`, `GESTURE_ACTIONS`, `DEFAULT_CONFIG`, `DEFAULT_ACTION_MAP`, `createHandLandmarker`
65
60
 
66
- ## API
67
-
68
- | Export | Description |
69
- |--------|-------------|
70
- | `HandStateManager` | Main state machine — `processLandmarks(landmarks)` → `{ state, rotation }` |
71
- | `HandGestureDetector` | Low-level gesture detection |
72
- | `HAND_STATES` | State constants (`open`, `closed`, `swipe_next`, …) |
73
- | `LANDMARKS` | MediaPipe landmark indices |
74
- | `HAND_CONNECTIONS` | Landmark pairs for debug drawing |
75
- | `DEFAULT_CONFIG` | Default configuration object |
76
- | `createHandLandmarker` | MediaPipe setup with GPU→CPU fallback |
77
-
78
- ## Hand states
79
-
80
- - `not_detected` — no hand in frame
81
- - `waiting` — hand lost for extended period
82
- - `starting` — cooldown after re-detection
83
- - `open` — open palm (zoom)
84
- - `closed` — closed fist
85
- - `pointing` — index finger extended
86
- - `flipping` — middle finger gesture
87
- - `swipe_next` / `swipe_previous` — horizontal swipe while pointing
61
+ Types: `HandConfig`, `GestureResult`, `HandState`, `GestureAction`, `Landmark`, `ActionMap`, …