How nischi/mmm-face-reco-dnn works
Project Type and Purpose
• This is a MagicMirror² module (JavaScript/Node.js front‑end + Node helper) that uses Python scripts (face_recognition, OpenCV, dlib) to detect and recognize faces via a Raspberry Pi camera.
• Purpose: show/hide MagicMirror modules based on who is in front of the mirror.
Main Components
A. MagicMirror² Core
• Hosts all modules, renders the UI, handles notifications bus.
B. MMM‑Face‑Reco‑DNN Front‑End (MMM‑Face‑Reco‑DNN.js)
• Configures display classes and handles incoming notifications (USERS_LOGIN, USERS_LOGOUT).
C. Node Helper (node_helper.js)
• Periodically triggers face recognition (checkInterval).
• Spawns Python processes for detection/encoding.
• Sends results back to MagicMirror via notifications.
D. Python Face‑Recognition Engine
• Scripts in tools/ (encode.py, recognition.py, takesPictures.py).
• Uses libraries: face_recognition, OpenCV (picamera2), dlib, numpy.
• Reads/writes: dataset/ (input images), model/haarcascade_frontalface_default.xml, model/encodings.pickle.
E. Hardware & Environment
• Raspberry Pi camera (via picamera2).
• Python virtual environment or system Python with required libraries.
F. Data Stores
• dataset/ (user subfolders with images).
• model/encodings.pickle (embeddings).
• Haar cascade XML (face detection).
Relationships & Data Flow
1. Front‑End sets checkInterval → Node Helper
2. Node Helper → (child_process) → Python recognition.py
3. Python script:
– Grabs image from Pi camera
– Detects faces (Haar or DNN)
– Computes embeddings, compares to encodings.pickle
– Returns list of recognized / unknown faces
4. Node Helper receives results → emits MagicMirror notifications (USERS_LOGIN, USERS_LOGOUT) → Front‑End
5. Front‑End updates module classes (known/unknown/noface) → MagicMirror² shows/hides modules
Architectural Patterns & Design Principles
• Modular separation: UI layer (JS) / orchestration (Node) / compute engine (Python).
• IPC via child processes and MagicMirror notification bus.
• Configuration-driven: model paths, detection method, classes.
• Extensibility: tools/ scripts for dataset management and encoding.
Essential Elements
– Arrowheads for data/control flow
– Note configuration inputs (config.js parameters)