Detect Emotion <script> const video = document.getElementById('video'); // Load the face-api models Promise.all([ faceapi.nets.tinyFaceDetector.loadFromUri('https://cdn.jsdelivr.net/npm/face-api.js/models'), faceapi.nets.faceExpressionNet.loadFromUri('https://cdn.jsdelivr.net/npm/face-api.js/models') ]).then(startVideo); function startVideo() { navigator.mediaDevices.getUserMedia({ video: {} }) .then(stream => { video.srcObject = stream; }) .catch(err => console.error("Camera access denied:", err)); } async function detectCameraEmotion() { const detections = await faceapi.detectAllFaces(video, new faceapi.TinyFaceDetectorOptions()) .withFaceExpressions(); if (detections.length > 0) { const emotions = detections[0].expressions; const highestEmotion = Object.keys(emotions).reduce((a, b) => emotions[a] > emotions[b] ? a : b); document.getElementById('result').textContent = `Detected Emotion: ${highestEmotion}`; } else { document.getElementById('result').textContent = "No face detected!"; } } </script>
Popular repositories Loading
-
-
face-recognition-javascript-webcam-faceapi
face-recognition-javascript-webcam-faceapi PublicForked from computervisioneng/face-recognition-javascript-webcam-faceapi
JavaScript
-
face-api.js
face-api.js PublicForked from justadudewhohacks/face-api.js
JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
TypeScript
Something went wrong, please refresh the page to try again.
If the problem persists, check the GitHub status page or contact support.
If the problem persists, check the GitHub status page or contact support.