Inspiration

The inspiration behind the Face Emotion Detector was the desire to bridge the gap between human emotion and digital interaction. In an increasingly digital world, technology often lacks the ability to understand and react to human feelings. We wanted to explore how we could use the power of modern web technologies and machine learning to create more empathetic and responsive applications. The idea of a web browser being able to recognize a smile, a frown, or a look of surprise in real-time was a fascinating challenge that could unlock new possibilities for user experience, accessibility, and interactive entertainment.

What it does

This project is a web-based, real-time face emotion detector. It uses a device's webcam to capture video, identifies a human face within the video stream, and analyzes the facial expressions to predict the current emotion. The application overlays the detected emotion (such as "Happy," "Sad," "Angry," "Surprised," "Neutral") directly onto the video feed, providing instant feedback to the user. The entire process runs locally in the user's browser, ensuring privacy and speed as no data is sent to a server for processing.

How we built it

The application is built entirely using front-end web technologies, making it accessible to anyone with a modern web browser.

HTML: We used semantic HTML5 to structure the application. This includes a element to render the live feed from the webcam and a element positioned directly on top of the video to draw the detection boxes and display the predicted emotion.

CSS: We used modern CSS for styling, employing Flexbox and Grid to create a clean, centered, and responsive layout that works well on different screen sizes. The styling ensures that the canvas overlay perfectly aligns with the video element for accurate annotations.

JavaScript: The core logic is powered by JavaScript.

Webcam Access: We used the navigator.mediaDevices.getUserMedia() API to request access to the user's camera and stream the video feed into the HTML element.

Face Detection Model: The magic behind the detection is the face-api.js library, which is a powerful and easy-to-use JavaScript module for face detection and facial landmark recognition, built on top of TensorFlow.js.

Implementation: We load several pre-trained models from face-api.js for detecting face landmarks and expressions. Once the models are loaded and the video starts playing, we use a setInterval loop to continuously grab the current frame from the video, detect a face, and run the expression analysis on it. The results are then drawn onto the canvas.

Challenges we ran into

One of the biggest challenges was performance. Running real-time face and emotion detection is computationally intensive and can be taxing on the user's CPU, especially on less powerful devices. We had to find a balance between the detection frequency and smoothness to avoid a laggy user experience.

Another challenge was the initial loading time. The pre-trained machine learning models are several megabytes in size, and we had to implement a loading screen to let the user know that the application was starting up, rather than presenting them with a blank, unresponsive page. Finally, ensuring consistent behavior and handling camera permissions gracefully across different web browsers required careful testing and error handling.

Accomplishments that we're proud of

We are particularly proud of creating a fully client-side AI application. The fact that all the complex machine learning processing happens directly in the browser without needing a powerful server backend is a significant achievement. This not only makes the application fast but also completely private and secure for the user. We were also proud of successfully integrating a complex library like face-api.js and creating a smooth, real-time user interface that provides immediate and engaging feedback.

What we learned

This project was a deep dive into the world of browser-based machine learning. We learned how to leverage powerful APIs like WebRTC (getUserMedia) for hardware interaction and how to integrate TensorFlow.js-based libraries like face-api.js into a web application. More importantly, we learned about the practical challenges of deploying AI models on the client-side, including managing model sizes, optimizing performance, and thinking critically about user experience from the moment the page loads.

What's next for Face Detector

The future for this project is exciting. We envision several potential enhancements:

Emotion Tracking Over Time: Instead of just showing the current emotion, we could track emotional changes over a period and visualize the data.

Integration with Other Apps: The emotion data could be used to control other applications. Imagine a music player that suggests songs based on your mood or an e-learning platform that adapts its difficulty based on a student's expression of confusion or understanding.

Improved Models: We could explore using different or custom-trained models to detect a wider range of nuanced emotions or improve accuracy under various lighting conditions.

Accessibility Features: The technology could be used to help individuals who have difficulty recognizing social cues by providing them with real-time feedback.

Built With

Share this project:

Updates