{"id":28762234,"url":"https://github.com/alfa-echo-niner-ait/drowsiness-detection","last_synced_at":"2026-04-13T17:01:56.093Z","repository":{"id":295086621,"uuid":"988921854","full_name":"alfa-echo-niner-ait/drowsiness-detection","owner":"alfa-echo-niner-ait","description":"A web-based drowsiness detection system that uses facial landmarks from webcam video to detect eye closure using Eye Aspect Ratio (EAR). Works in both desktop and mobile browsers.","archived":false,"fork":false,"pushed_at":"2025-05-23T14:26:02.000Z","size":63036,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-17T08:07:31.887Z","etag":null,"topics":["flask","mediapipe","opencv","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alfa-echo-niner-ait.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-23T09:26:23.000Z","updated_at":"2025-05-23T14:46:01.000Z","dependencies_parsed_at":"2025-05-23T16:11:21.188Z","dependency_job_id":null,"html_url":"https://github.com/alfa-echo-niner-ait/drowsiness-detection","commit_stats":null,"previous_names":["alfa-echo-niner-ait/safedrive-ai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alfa-echo-niner-ait/drowsiness-detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfa-echo-niner-ait%2Fdrowsiness-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfa-echo-niner-ait%2Fdrowsiness-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfa-echo-niner-ait%2Fdrowsiness-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfa-echo-niner-ait%2Fdrowsiness-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alfa-echo-niner-ait","download_url":"https://codeload.github.com/alfa-echo-niner-ait/drowsiness-detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alfa-echo-niner-ait%2Fdrowsiness-detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31761996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","mediapipe","opencv","python"],"created_at":"2025-06-17T08:07:31.760Z","updated_at":"2026-04-13T17:01:56.076Z","avatar_url":"https://github.com/alfa-echo-niner-ait.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Driver Drowsiness Detection Web App  \n\n**Real-Time Eye Closure Detection Using MediaPipe, OpenCV \u0026 Flask**\n\nA web-based drowsiness detection system that uses facial landmarks from webcam video to detect eye closure using **Eye Aspect Ratio (EAR)**. Works in both **desktop and mobile browsers**.\n\n\u003cdiv align =\"center\"\u003e\n\n![Preview](screenshots/preview.png)\n\n\u003c/div\u003e\n\n### Perfect for:\n\n🧠 Research in driver safety\n\n💻 Computer vision demos\n\n📱 Mobile-friendly applications\n\n📐 EAR-based fatigue detection\n\n\n---\n\n## 🔍 Overview\n\nThis project implements a lightweight, real-time **driver drowsiness detection system** using:\n\n- **MediaPipe FaceMesh** – for 468 facial landmarks\n- **OpenCV** – For image processing, drawing eye landmarks, and video manipulation\n- **Flask** – Backend processing\n- **HTML + JavaScript** – Frontend UI with live webcam access\n- **Eye Aspect Ratio (EAR)** – For blink/drowsiness detection\n- **Audio alert** – Visual + sound alert when eyes are closed too long\n\nNo need for extra hardware, all we need is a **webcam-enabled device** and a modern **browser**.\n\n---\n\n## 🧩 Features\n\n✅ Real-time webcam feed  \n✅ EAR calculation per frame  \n✅ Visual + audio alert on drowsiness  \n✅ Responsive design (mobile/desktop friendly)  \n✅ Easy setup – no complex dependencies  \n✅ Works over local network or via Ngrok  \n\n---\n\n## 🛠️ Tools Versions\n\n| Tool | Version |\n|------|---------|\n| Python | 3.12.1 |\n| Flask | 3.1.1 |\n| MediaPipe | 0.10.21 |\n| OpenCV | 4.11.0.86 |\n| SciPy | 1.15.3 |\n| Base64 | Built-in |\n| ngrok (optional) | For HTTPS tunneling |\n\n---\n\n## 🚀 How to Run\n\n1. Clone or download the repo\n\n2. Install dependencies:\n\n```bash\npip install -r requirements.txt\n```\nOr,\n\n```bash\npip install flask mediapipe opencv-python numpy scipy\n```\n\n3. Start the Flask server:\n\n```bash\npython app.py\n```\n\n4. Open browser at:\n\n```\nhttp://localhost:5000\n```\n\n5. (Optional) Use [Ngrok](https://ngrok.com/downloads/) for mobile testing:\n\n```bash\nngrok http 5000\n```\n\nOpen the generated URL on any device.\n\n---\n\n## 🖥️ Usage\n\n1. Allow camera access when prompted.\n2. The app will calculate EAR every 200ms.\n3. If EAR \u003c threshold (`0.22`) for 10+ frames → \"DROWSINESS DETECTED!\" alert appears.\n4. Audio alarm plays automatically.\n5. Once eyes reopen, status resets to \"Awake\".\n\n---\n\n## ⚙️ Technical Details\n\n### Eye Landmarks Used\n\n```python\nLEFT_EYE = [362, 385, 387, 263, 373, 380]\nRIGHT_EYE = [33, 160, 158, 133, 153, 144]\n```\n\n### EAR Formula\n\n$$\n\\text{EAR} = \\frac{(A + B)}{(2 \\times C)}\n$$\n\nWhere:\n- $ A = \\text{Top-left to bottom-left vertical distance} $\n- $ B = \\text{Top-right to bottom-right vertical distance} $\n- $ C = \\text{Left corner to right corner horizontal distance} $\n\nThreshold: `0.22`  \nFrame Count to Trigger Alert: `10`\n\n---\n\n## 🎨 UI Preview\n\n| Feature | Description |\n|--------|-------------|\n| Webcam Video | Flipped to match natural view |\n| EAR Display | Real-time eye aspect ratio shown |\n| Status Text | Shows \"Awake\" or \"Drowsy\" |\n| Red Glow + Flash | Visual alert when drowsy |\n| Audio Alert | Plays sound when drowsiness detected |\n\n---\n\n## 📋 License\n\nMIT License – see [LICENSE](LICENSE)\n\n---\n\n## 📬 Feedback \u0026 Contributions\n\nContributions are welcome! Feel free to open issues or PRs.\n\n👤 **Maintainer**: Ayub Ali Emon (emon@sdust.edu.cn), member of  [CogTwins Lab](https://cogtwins.github.io/), Shandong University of Science and Technology.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfa-echo-niner-ait%2Fdrowsiness-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falfa-echo-niner-ait%2Fdrowsiness-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falfa-echo-niner-ait%2Fdrowsiness-detection/lists"}