A lightweight JavaScript framework for real-time face and gesture detection in web browsers using MediaPipe. This framework makes it easy to implement and track custom gestures using webcam input.
- Real-time face detection and mesh rendering
- Hand gesture recognition
- Built-in gesture detection:
- Thinking (hand on chin)
- Silence (finger on lips)
- Mind Blown (hands expanding from temples)
- Thumbs Up
- Extensible gesture system
- Webcam integration
- GPU-accelerated processing
- Colored face mesh visualization
-
Clone this repository:
git clone [email protected]:paddleboard-ai/glance.git cd glance
-
Start a local web server:
python3 -m http.server # or use any other local server of your choice
-
Open
http://127.0.0.1:8000/face.html
in your browser and allow webcam access
├── gestures/
│ ├── mind_blown.js
│ ├── silence.js
│ ├── thinking.js
│ └── thumbs_up.js
├── face.html
├── script.js
├── gesture_tracker.js
└── utils.js
face.html
: Main entry point and UIscript.js
: Core detection and rendering logicgesture_tracker.js
: Gesture management and coordinationutils.js
: Common utility functions
Each gesture is implemented as a separate class in the gestures/
directory. All gestures follow a common pattern:
- Class-based implementation
- Constructor for initialization
- Tracking method that returns boolean (gesture detected or not)
- Utility methods specific to the gesture
-
Create a new file in the
gestures/
directory:// gestures/my_gesture.js import { Utils } from '../utils.js'; class MyGesture { constructor() { this.utils = new Utils(); this.isActive = false; this.startTime = null; } trackMyGesture(handLandmarks, faceData, currentTime) { // Implement gesture detection logic return false; // or true when detected } } export { MyGesture };
-
Add the gesture to
gesture_tracker.js
:import { MyGesture } from './gestures/my_gesture.js'; // Add to GESTURE_NAMES const GESTURE_NAMES = Object.freeze({ // ... existing gestures ... MY_GESTURE: 'My Gesture' }); class GestureTracker { constructor() { // ... existing initialization ... this.myGesture = new MyGesture(); } // Add tracking method trackMyGesture(handLandmarks, currentTime) { if (this.myGesture.trackMyGesture(handLandmarks, this.faceData, currentTime)) { if (!this.activeGestures.includes(GESTURE_NAMES.MY_GESTURE)) { this.activeGestures.push(GESTURE_NAMES.MY_GESTURE); } return; } else { this.activeGestures = this.activeGestures.filter(g => g !== GESTURE_NAMES.MY_GESTURE); } } }
-
Update the detection loop in
script.js
to call your new gesture tracker.
The framework uses MediaPipe's Vision tasks for:
- Face landmark detection (468 points)
- Hand landmark detection (21 points per hand)
- Gesture recognition
Models are loaded from MediaPipe's CDN, and ran in a WASM container.
- Uses GPU delegation when available
- Implements cooldown periods for complex gestures
- Frame-by-frame processing with requestAnimationFrame
- Requires WebGL support
- Needs webcam access
- Tested on modern versions of Chrome, Brave, and Edge
- Mobile browser support may vary
Contributions are welcome! Areas for improvement include:
- Additional gestures
- Performance optimizations
- Mobile browser support
- UI improvements
- Documentation