This project is an interactive computer vision and audio system that:
- detects facial landmarks from a webcam stream,
- classifies facial emotion with a fine-tuned FER model, and
- maps emotion and facial geometry to expressive real-time music.
It was built for a computer vision course project and combines perception, temporal smoothing, and multimodal output (visual + audio).
The pipeline runs in real time:
vision.pycaptures webcam frames and extracts facial landmarks with MediaPipe.- The same module classifies emotion (
angry,disgust,fear,happy,neutral,sad,surprise) using a PyTorchefficientnetv2_smodel. mapping.pymaps emotion + facial features to musical parameters (tempo, instrument, scale, note, velocity, sustain, pan, etc.).audio.pyplays music through either:- system MIDI (preferred, low latency), or
- a software synth fallback.
main.pyrenders the HUD, handles keyboard controls, and optionally records evaluation stats.
main.py- main real-time applicationlauncher.py- Tkinter launcher UI for selecting modes/settingsvision.py- webcam capture, landmarks, FER inference, feature extractionmapping.py- facial expression to music mapping logicaudio.py- MIDI/synth audio backendsevaluation.py- emotion metrics and latency profiler utilitiestest_audio.py- audio-only demo (no camera required)test_offline.py- offline FER evaluation scriptmodels/- model config and class mapping (best_model.pthexpected here)face_landmarker.task- MediaPipe face landmarker model assetrequirements.txt- Python dependencies
- Python 3.10+ recommended
- Webcam (for real-time vision modes)
- Audio output device
- Optional: system MIDI synthesizer/device for best latency
Install project dependencies:
pip install -r requirements.txtIf not already installed in your environment, install PyTorch + torchvision for your system:
pip install torch torchvisionFrom the project root:
python -m venv .venvActivate the environment:
- Windows PowerShell:
.\.venv\Scripts\Activate.ps1- macOS/Linux:
source .venv/bin/activateThen install dependencies:
pip install -r requirements.txt
pip install torch torchvisionpython launcher.pyThe launcher lets you choose:
- full mode (vision + audio),
- audio-only test mode,
- vision-only mode,
- evaluation mode,
- camera/FPS/smoothing settings, and audio backend.
python main.pyUseful flags:
--synth- force software synth backend--eval- enable ground-truth labeling/evaluation mode--latency- print latency summary every 5 seconds--no-audio- vision-only debug mode--camera <idx>- camera index (default0)--fps <n>- target FPS cap (default30)--smooth <0..1>- temporal smoothing alpha (default0.3)--interval <seconds>- note trigger interval (default0.4)
Example:
python main.py --eval --latency --camera 0 --fps 30Q/ESC- quitP- pause/resume audioR- reset evaluator/profilerS- print latency summaryE- print emotion evaluation reportL- cycle ground-truth label in eval modeM- toggle landmark dotsL(non-eval) - toggle mesh linesC- toggle confidence barsF- toggle fullscreenTAB- recalibrate baseline facial measurements
python test_audio.pyUse this to validate mapping + playback without webcam dependencies.
Smoke test (no dataset required):
python test_offline.py --smokeFER2013 CSV mode:
python test_offline.py --fer2013 /path/to/fer2013.csv --split PublicTest --samples 1000Folder dataset mode:
python test_offline.py --testdir /path/to/test_dataset --samples 1000Expected FER2013 labels:
0 angry1 disgust2 fear3 happy4 sad5 surprise6 neutral
session_stats.json- written after sessions (used by launcher statistics popup)fer2013_eval_results.csv- offline FER evaluation recordsfolder_eval_results.csv- folder-based offline evaluation records
- Camera not opening: verify camera index (
--camera 0,--camera 1, ...). - No audio output: switch to software synth (
--synth). - Missing model file: ensure
models/best_model.pthexists. - Slow runtime: reduce FPS (
--fps 15or24) and/or increase smoothing. - Missing PyTorch errors: install
torch torchvisionin the active environment.
CS6384 Computer Vision course project, combining:
- MediaPipe face landmarks,
- PyTorch FER classification, and
- real-time generative music mapping.