I’ve ported a project that detects eye movement patterns during REM sleep and triggers audio and visual alerts to promote lucidity: https://github.com/lucidcode/Halovision-INSPEC.
The REM-detection algorithm runs on the firmware on the camera with an IR lens and uses facial detection to narrow down the region where to look for eye movements. When enough eye movements are counted within a timeframe it flashes the LEDs asynchronously. It also streams the video feed to an app in real-time over Wi-Fi or more slowly over BLE where it can play audio tracks.