Emotion Detection Using Image Processing in Python
Emotion Detection Using Image Processing in Python
2018 5 International Conference on “Computing for Sustainable Global Development”, 14 th - 16th March, 2018
th
Bharati Vidyapeeth's Institute of Computer Applications and Management (BVICAM), New Delhi (INDIA)
Abstract—In this work,user’s emotion using its facial The method involves converting an image into a 2D Matrix.
expressions will be detected. These expressions can be derived
from the live feed via system’s camera or any pre-existing image It consists of three basic steps [2]:
available in the memory.Emotions possessed by humans can be 1.) Scanning the image: a raw image is acquired which
recognized and has a vast scope of study in the computer vision has to be processed. It can be expressed in form of pixels as
industry upon which several researches have already been done. stated above.The aim of this step is to extract information
The work has been implemented using Python (2.7), Open Source
which is suitable for computing.
Computer Vision Library (OpenCV) and NumPy. The scanned
image (testing dataset) is being compared to training dataset and 2.) Processing and Enhancing it: -the image is
thusemotion is predicted. The objective of this paper is to develop converted into digital form by using a digitizer which samples
a system which can analyze the image and predict the expression and quantizes the input signals. The rate of sampling should be
of the person. The study proves that this procedure is workable high for good resolution and high quantization level for human
and produces valid results. perception of different shades using different using gray-scale
Keywords—Face Recognition, Image Processing, Computer 3.) The obtained result describes the property of the
Vision, Emotion Detection, OpenCV image and further classifies the image.
Conversion of Color Image to Gray Scale
I. INTRODUCTION TO IMAGE PROCESSING There are basically two methods to convert a color image to a
gray scale image [8]:
In order to get an enhanced image and to extract some A.) Average Method
useful information out of it, the method of Image Processing
can be used. It is a very efficient way through which an image In Average method, the mean is taken of the three colors i.e.
can be converted into its digital form subsequently performing Red, Blue & Green present in a color image. Thus, we get
various operations on it. This is a technique similar to signal Grayscale= (R+G+B)/3;
processing, in which the input given is a 2D image, which is a
collection of numbers ranging from 0 to 255 which denotes the But what happens sometimes is instead of the grayscale image
corresponding pixel value. [8] we get the black image. This is because we in the converted
image we get 33% each of Red, Blue & Green.
TABLE 1:THIS IS A 2D ARRAY DEPICTING THE PIXELS OF A
SAMPLE IMAGE Therefore, to solve this problem we use the second method
called Weighted Method or Luminosity Method.
134 21 107
64 37 78
B) Weighted or Luminosity Method
42 4 13
To solve the problem in Average Method, we use Luminosity
method. In these method, we decrement the presence of Red
Color and increment the color of Green Color and the blue GPU coding. In GPU Module, we cannot change the features
color has the percentage in between these two colors. of an image directly, rather we have to copy the original image
followed by editing it.
Thus, by theequation [8],
Fig.2 Flowchart for Emotion Algorithm [13]
Grayscale=((0.3 * R) + (0.59 * G) + (0.11 * B)).
We use this because of the wavelength patterns of these colors.
Blue has the least wavelength while Red has the maximum
wavelength.
II. Review of Literature
1. Different Strengths & Weaknesses were noted in the
emotion recognition system by Mr. Ashwini, Mr. Jacob and
Dr. Jubilant [14] of St. Joseph’s College of Engineering.
2.Mr. ArunaChakraborty, Mr. Amit Konar, Mr. Uday
Kumar Chakraborty, and Mr. Amita Chatterjee in. Emotion
Recognition from Facial Expressions and Its Control Using
Fuzzy Logic [15] explained that this fuzzy approach that
has accuracy of about 90%.
3. Strengths and weaknesses of facial expression classifiers
and acoustic emotion classifiers were analyzed by Carlos
Busso, Zhigang Deng, SerdarYildirim, MurtazaBulut, Chul
Min Lee, Abe Kazemzadeh, Sungbok Lee, Ulrich Neumann
and Shrikanth Narayanan. [1].
Result=>
direc/filename1
direc/filename2
direc/filename3
direc/filename4
direc/filename5
direc/files
Fig.3 Flowchart for Emotion Detection
b) Question Mark(?): It represents or
finds a single missing character
For e.g.
import glob
A. A. Neutral
B. B. Happy
C. C. Anger
D. D. Disgust
E. Surprise
F. Fear
G. Sad
H. Contempt
Fig.4 Output of a sample image [9]
III. VI. STEPS INVOLVED TO PERFORM EMOTION DETECTION VII. Cohn-Kanade AU-CODED EXPRESSION DATABASE
USING OPENCV-PYTHON:
This is one of the Databases that can be used for emotion
1)After successfully installing all the necessary softwares, we detection. It’s a Database having numerous types of emotions
must start by creating a Dataset. Here, we can create our own [6]. This database is currently available in two different
dataset by analyzing group of images so that our result is categories while the third one is under development stage.
accurate and there is enough data to extract sufficient
information. Or we can use an existing database. The first version is labeled by “CK” while the second version
is labeled as “CK+”. The CK version starts by detecting the
2)The dataset is then organized into two different
neutral emotion and then advances to the other higher
directories. First directory will contain all the images and the
emotions.
second directory will contain all the information about the
different types of emotions. With the release of second type of this database, the frequency
3)After running the sample images through the of processes increased by approximately 25% and the
python code, all the output images will be stored into another frequency of subjects by approximately 30% [6].
directory, sorted in the order of emotions and its subsequent
encoding. The third release is on the verge of development as which will
have both the features of CK and CK+ Database, for e.g.
4)Different types of classes can be used in OpenCV for adding integrated 30 degrees of rotation from the front.
emotion recognition, but we will be mainly using Fisher Face
one. [1] IV. VIII. APPLICATIONS AND FUTURE SCOPE
5)Extracting Faces:OpenCV provides four predefined Computer Vision is a very vast field which is still under
classifiers, so to detect as many faces as possible, we use these developmental phase. Research work in this field is going at a
classifiers in a sequence [1] rapid phase.
6)The dataset is split into Training set and Classification set.
The training set is used to teach the type of emotions by Emotion detection is an inseparable part of computer vision.
extracting information from a number of images and the Loads of tasks and processes can be performed if one can
classification set is used to estimate the classifier performance. become aware about the intricacies and endless possibilities
7)For best results, the images should be of exact same offered under the field of emotion detection.
properties i.e. size.
Some common and widely used applications of emotion
8)The subject on each image is analyzed, converted to detection are:
grayscale, cropped and saved to a directory [1]
9)Finally, we compile training set using 80% of the test data A. App and product development
and classify the remaining 20% on the classification set. Emotion recognition can play a huge role in optimizing
Repeat the process to improve efficiency [1]. various software engineering processes which comprises of
testing of ease with which a product can be used. It’s a long-
established fact that level of comfort with different software
products depends hugely upon human emotions. A products
overall look and feel can also alter human feelings which in
turn makes the person buy the product or not. Thus,
researching about different emotional states of a human body We humans also sometimes make a mistake while recognizing
and how it is influenced by usage of different products is a someone’s emotion so is our program. The optimum accuracy
matter of prime importance for related industry professionals. was nearly 83%.