Skip to content

About

Mobile Technology project on Computer Vision topic. An app that detect your face and also your emotion. From your dominant emotion, it will fetch spotify music recommendation.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Emotion-Based Music Recommendation System 🎶😊

This project combines facial emotion detection with music recommendation. Using a webcam, the system detects a user’s emotion and then suggests music tailored to that emotion from a Spotify dataset.

Features

  • Real-Time Emotion Detection: Uses a webcam feed to detect emotions in real-time with DeepFace.
  • Music Recommendation: Based on the detected emotion, recommends songs with relevant features (e.g., high valence for happy emotions).
  • Spotify Integration: Generates a Spotify search link to easily find and listen to the recommended songs.

Table of Contents

  1. Getting Started
  2. Installation
  3. Usage
  4. Dataset
  5. Code Explanation
  6. Contributing

Getting Started

This project requires:

  • A webcam for real-time video capture.
  • A trained face recognizer model (LBPH) and a Haar Cascade classifier.
  • A Spotify music dataset to use for recommendations.

Prerequisites

  • Python 3.x
  • Kaggle account to download the Spotify music dataset

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/face_recognition.git
    cd face_recognition
  2. Install the required libraries:

    pip install opencv-contrib-python deepface pandas --user
  3. Download the Spotify dataset from Kaggle and place it in the project directory:

  4. Prepare the face model:

    • Ensure that the haarcascade_frontalface_default.xml file is available for face detection.
    • Run python face_create_dataset.py to create dataset consist of your own face.
    • Then train the dataset model by running python face_training.py

Usage

To start the application:

python face_recognition_v2.py
  1. Emotion Detection: The system scans the face for 8 seconds, then identifies the most frequently detected emotion.
  2. Music Recommendation: Based on the detected emotion, the system suggests five songs and generates Spotify links.

Dataset

The dataset is a Spotify music dataset containing features like valence, energy, danceability, etc., essential for emotion-based recommendations. The dataset can be downloaded from Kaggle:

Spotify Dataset - Kaggle

Ensure the file is named songs_normalize.csv.


Code Explanation

Face Recognition and Emotion Detection

The script uses OpenCV and DeepFace to recognize faces and detect emotions. The program captures video frames, processes them for faces, and then analyzes emotions based on detected faces.

# Set up camera capture
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

Emotion Counter

The system captures and counts emotions over 10 seconds to determine the most common emotion detected. But you can customize it based on your machine capabilities

from collections import Counter
emotion_counts = Counter()
scan_duration = 10  # seconds

Song Recommendation

Based on the dominant emotion detected, the system filters songs from the dataset with matching features.

# Recommend songs function
def recommend_songs(emotion, num_songs=5):
    # Filters for happy, sad, fear, angry, surprised, and neutral emotions
    # Each emotion corresponds to specific song features

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a pull request

Acknowledgments

About

Mobile Technology project on Computer Vision topic. An app that detect your face and also your emotion. From your dominant emotion, it will fetch spotify music recommendation.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages