Skip to content

In this project, you will know how to build a smiles detection system in an easy way

Notifications You must be signed in to change notification settings

trinhdoduyhungss/Detect_emotion_and_motion_simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Introduction

Facial emotion identification was a familiar problem in the world of computer vision. Although we have already many libraries that can help create an emotion detection system more convenient than in the past, we will depend on the ability of that and its pre-trained models. So, if you want to expand the recognition capabilities to your liking in the easiest way, welcome to my project. I will choose a very humanistic theme that is "Smiles".

Ideas

The main idea here is that we will define the shape of the mouth and the threshold instead of using advanced algorithms like Machine Learning or Deep Learning for smile detection.

About the maths

I hope you can understand some of the formulas below:

About the code

You need to install the libraries below:

  • Dlib pip install dlib

  • Opencv pip install opencv-python

  • Dowload the file shape_predictor_68_face_landmarks.dat tại đây
    The landmark file that look like this : Example of facial markers

    Each white point in the image is a landmark for your face, the effect of this file will give us a model that defines 68 landmarks on the face, we will use the markers to define the shape of the mouth!

Let's coding:

Import the libraries
import dlib
import cv2
from math import sqrt
Load file shape_predictor_68_face_landmarks.dat with dlib for face and markers detection
predictor = dlib.shape_predictor('./shape_predictor_68_face_landmarks.dat')
detector = dlib.get_frontal_face_detector()
Turn on real-time opencv function
vs = cv2.VideoCapture(0)
while True:
Get frames
check, frame = vs.read()

Convert image to gray image due to that is input of the dlib

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
Draw rectangle
for rect in dets:
        x = rect.left()
        y = rect.top()
        w = rect.right()
        h = rect.bottom()
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 1)
Draw landmark
landmark = predictor(gray, rect)
Get markers of mouth
       for k, d in enumerate(landmark.parts()):
           if(k>=60 and k<=68):
               lines.append((d.x,d.y))

markers of mouth

Calculation

...

Read more at my Vietnamese post on Viblo

About

In this project, you will know how to build a smiles detection system in an easy way

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages