A real-time face detection and recognition system using face-api.js with Node.js backend and web UI.
- ✅ Real-time face detection with webcam
- ✅ Multiple face detection simultaneously
- ✅ Face recognition with custom training
- ✅ Live bounding boxes with names
- ✅ Train new faces through the UI
- ✅ Persistent storage of face data
- ✅ FPS counter and statistics
- ✅ Responsive web interface
- Node.js (v14 or higher)
- Webcam
- Modern web browser (Chrome, Firefox, Edge)
- Install dependencies:
npm install-
Download face-api.js models:
- Visit: https://github.com/justadudewhohacks/face-api.js-models
- Download these folders and place them in
public/models/:ssd_mobilenetv1_modelface_landmark_68_modelface_recognition_model
Your directory structure should look like:
public/ └── models/ ├── ssd_mobilenetv1_model/ │ ├── model.json │ └── weights files... ├── face_landmark_68_model/ │ ├── model.json │ └── weights files... └── face_recognition_model/ ├── model.json └── weights files...
- Start the server:
npm start- Open your browser and navigate to:
http://localhost:3000
-
Click "Start Camera" to begin face detection
-
To train new faces:
- Enter a person's name in the input field
- Make sure their face is visible in the camera
- Click "Capture Face"
- Repeat 2-3 times for better accuracy
-
The system will now recognize trained faces in real-time!
- Face Detection: Uses SSD MobileNet V1 to detect faces in video frames
- Landmark Detection: Identifies 68 facial landmark points for each face
- Face Recognition: Computes 128-dimensional face descriptors and matches against trained faces
- Real-time Processing: Continuously processes video frames and displays results
POST /api/save-face- Save a new face descriptorGET /api/get-faces- Get all trained facesDELETE /api/delete-face/:name- Delete a person's face data
- Use good lighting for better detection
- Face the camera directly
- Train multiple samples (2-3) per person for better accuracy
- Adjust
minConfidencein app.js for sensitivity
Models not loading:
- Make sure you downloaded all model files
- Check that folders are in
public/models/ - Verify file names match exactly
Camera not working:
- Allow camera permissions in browser
- Check if another app is using the camera
- Try a different browser
Poor recognition accuracy:
- Capture more training samples (3-5 per person)
- Ensure good lighting conditions
- Make sure face is clearly visible and frontal
- face-api.js: Face detection and recognition
- TensorFlow.js: Neural network operations
- Express.js: Web server
- Vanilla JavaScript: Frontend logic
- HTML5/CSS3: User interface
MIT