Human Emotion Detection from Image
Introduction
This code can detect human emotion from image. First, it takes an image, then by skin color segmentation, it detects human skin color, then it detect human face. Then it separates the eyes & lip from the face. Then it draws bezier curve for eyes & lips. Then it compares the bezier curve of eyes and lips to the bezier curves of eyes & lips that are stored in the data base. Then it finds the nearest bezier curse from the data base & gives that data base stored bezier curve emotion as this image emotion.
How Does It Work?
Skin Color Segmentation
For skin color segmentation, first we contrast the image. Then we perform skin color segmentation.
Pic-1.PNG
Then, we have to find the largest connected region. Then we have to check the probability to become a face of the largest connected region. If the largest connected region has the probability to become a face, then it will open a new form with the largest connected region. If the largest connected regions height & width is larger or equal than 50 and the ratio of height/width is between 1 to 2, then it may be face.
Pic-2.PNG
Face Detection
For face detection, first we convert binary image from RGB image. For converting binary image, we calculate the average value of RGB for each pixel and if the average value is below than 110, we replace it by black pixel and otherwise we replace it by white pixel. By this method, we get a binary image from RGB image.
pic-10.PNG
Then, we try to find the forehead from the binary image. We start scan from the middle of the image, then want to find a continuous white pixels after a continuous black pixel. Then we want to find the maximum width of the white pixel by searching vertical both left and right site. Then, if the new width is smaller half of the previous maximum width, then we break the scan because if we reach the eyebrow then this situation will arise. Then we cut the face from the starting position of the forehead and its high will be 1.5 multiply of its width.
pic-11.PNG pic-12.PNG
In the figure, X will be equal to the maximum width of the forehead. Then we will have an image which will contain only eyes, nose and lip. Then we will cut the RGB image according to the binary image.
Eyes Detection
For eyes detection, we convert the RGB face to the binary face. Now, we consider the face width by W. We scan from the W/4 to (W-W/4) to find the middle position of the two eyes. The highest white continuous pixel along the height between the ranges is the middle position of the two eyes.
pic-13.PNG
Then we find the starting high or upper position of the two eyebrows by searching vertical. For left eye, we search w/8 to mid and for right eye we search mid to w – w/8. Here w is the width of the image and mid is the middle position of the two eyes. There may be some white pixels between the eyebrow and the eye. To make the eyebrow and eye connected, we place some continuous black pixels vertically from eyebrow to the eye. For left eye, the vertical black pixel-lines are placed in between mid/2 to mid/4 and for right eye the lines are in between mid+(w-mid)/ 4 to mid+3*(w-mid)/ 4 and height of the black pixel-lines are from the eyebrow starting height to (h- eyebrow starting position)/4. Here w is the width of the image and mid is the middle position of the two eyes and h is the height of the image. Then we find the lower position of the two eyes by searching black pixel vertically. For left eye, we search from the mid/4 to mid - mid/4 width. And for right eye, we search mid + (w-mid)/ 4 to mid+3*(w- mid)/ 4 width from image lower end to starting position of the eyebrow. Then we find the right side of the left eye by searching black pixel horizontally from the mid position to the starting position of black pixels in between the upper position and lower position of the left eye. And left side for right eye we search mid to the starting position of black pixels in between the upper position and lower position of right eye. The left side of the left eye is the starting width of the image and the right side of the right eye is the ending width of the image. Then we cut the upper position, lower position, left side and the right side of the two eyes from the RGB image.
pic-14.PNG
Lip Detection
For lip detection, we determine the lip box. And we consider that lip must be inside the lip box. So, first we determine the distance between the forehead and eyes. Then we add the distance with the lower height of the eye to determine the upper height of the box which will contain the lip. Now, the starting point of the box will be the ¼ position of the left eye box and ending point will be the ¾ position of the right eye box. And the ending height of the box will be the lower end of the face image. So, this box will contain only lip and may some part of the nose. Then we will cut the RGB image according the box.
pic-15.PNG
So, for detection eyes and lip, we only need to convert binary image from RGB image and some searching among the binary image.
pic-16.PNG
Apply Bezier Curve on Lip
In the lip box, there is lip and may be some part of nose. So, around the box there is skin color or the skin. So, we convert the skin pixel to white pixel and other pixel as black. We also find those pixels which are similar to skin pixels and convert them to white pixel. Here, if two pixels RGB values difference is less than or equal 10, then we called them similar pixel. Here, we use histogram for finding the distance between the lower average RGB value and higher average RGB value. If the distance is less than 70, then we use 7 for finding similar pixel and if the distance is getter than or equal 70 then we use 10 for finding similar pixel. So, the value for finding similar pixel depends on the quality of the image. If the image quality is high, we use 7 for finding similar pixel and if the image quality is low, we use 10.
pic-17.PNG
So, in the binary image, there are black regions on lip, nose and may some other little part which have a little different than skin color. Then we apply big connected region for finding the black region which contain lip in binary image. And we are sure that the big connected region is the lip because in the lip box, lip is the largest thing which is different than skin.
pic-18.PNG
Then we have to apply Bezier curve on the binary lip. For apply Bezier curve, we find the starting and ending pixel of the lip in horizontal. Then we draw two tangents on upper lip from the starting and ending pixel and also find two points on the tangent which is not the part of the lip. For the lower lip, we find two point similar process of the upper lip. We use Cubic Bezier curves for draw the Bezier curve of the lip. We draw two Bezier curve for the lip, one for upper lip and one for lower lip.
pic-19.PNG
Apply Bezier Curve on Eye
For apply Bezier curve on eyes, first we have to remove eyebrow from eye. For remove eyebrow, we search 1st continuous black pixel then continuous white pixel and then continuous black pixel from the binary image of the eye box. Then we remove the 1st continuous black pixel from the box and then we get the box which only contains the eye.
pic-20.PNG pic-21.PNG
Now, the eye box which contains only eye, has some skin or skin color around the box. So, we apply similar skin color like the lip for finding the region of eye. Then we apply big connect for finding the highest connected region and this is the eye because in the eye box, eye is the biggest thing which is not similar to the skin color.
pic-22.PNG pic-23.PNG
Then we apply the Bezier curve on the eye box, similar to the lip. Then we get the shape of the eye.
pic-24.PNG
Database and Training
In our database, there are two tables. One table “Person” is for storing the name of people and their index of 4 kinds of emotion which are stored in other table “Position”. In the “Position” table, for each index, there are 6 control points for lip Bezier curve, 6 control points for left eye Bezier curve, 6 control points for right eye Bezier curve, lip height and width, left eye height and width and right eye height and width. So, by this method, the program learns the emotion of the people.
pic-25.PNG
Emotion Detection
For emotion detection of an image, we have to find the Bezier curve of the lip, left eye and right eye. Then we convert each width of the Bezier curve to 100 and height according to its width. If the person’s emotion information is available in the database, then the program will match which emotion’s height is nearest the current height and the program will give the nearest emotion as output.
pic-26.PNG
If the person’s emotion information is not available in the database, then the program calculates the average height for each emotion in the database for all people and then get a decision according to the average height.
pic-27.PNG
ตรวจสอบอารมณ์มนุษย์จากภาพแนะนำรหัสนี้สามารถตรวจพบอารมณ์มนุษย์จากภาพ ครั้งแรก ใช้ภาพ แล้ว โดยแบ่งสีผิว ตรวจพบสีผิวมนุษย์ แล้วก็ตรวจพบใบหน้ามนุษย์ แล้ว ก็แยกตาและลิจากหน้า จากนั้น จะวาดเส้นโค้ง bezier สำหรับตาและริมฝีปาก จากนั้น จึงเปรียบเทียบเส้นโค้ง bezier ของดวงตาและริมฝีปากกับเส้นโค้ง bezier ของดวงตาและริมฝีปากที่เก็บอยู่ในฐานข้อมูล แล้วจะพบคำสาป bezier ที่ใกล้ที่สุดจากฐานข้อมูล และให้อารมณ์ที่เส้นโค้ง bezier เก็บฐานข้อมูลเป็นอารมณ์รูปนี้การทำงานหรือไม่แบ่งสีผิวการแบ่งสีผิว ก่อนเราความคมชัดภาพ เราดำเนินการแบ่งสีผิวรูปภาพ-1.PNGจากนั้น เราต้องค้นหาเชื่อมต่อภูมิภาคที่ใหญ่ที่สุด แล้ว เราต้องตรวจสอบความเป็นไปได้จะกลายเป็น ใบหน้าของภูมิภาคที่ใหญ่ที่สุดเชื่อมต่อ ถ้าเชื่อมต่อภูมิภาคที่ใหญ่ที่สุดมีความเป็นไปได้จะกลายเป็น ใบหน้า แล้วมันจะเปิดแบบฟอร์มใหม่ในภูมิภาคที่เชื่อมต่อที่ใหญ่ที่สุด ถ้าเชื่อมต่อภูมิภาคความสูง และความกว้างจะเท่า หรือใหญ่กว่า 50 และอัตราส่วนของความสูง/ความกว้างอยู่ระหว่าง 1-2 มันอาจจะหน้ารูปภาพ-2.PNGตรวจจับใบหน้าสำหรับการตรวจจับใบหน้า เราแปลงภาพไบนารีจากภาพ RGB สำหรับการแปลงรูปแบบไบนารี เราคำนวณค่าเฉลี่ยของ RGB แต่ละพิกเซล และถ้าค่าเฉลี่ยไม่ต่ำกว่า 110 เราแทนพิกเซลสีดำมิฉะนั้น เราแทนพิกเซลสีขาว โดยวิธีนี้ เรารับรูปแบบไบนารีจากภาพ RGBรูปภาพ-10PNGจากนั้น เราพยายามหาหน้าผากจากภาพไบนารี เราเริ่มสแกนจากกลางภาพ นั้นต้องการค้นหาพิกเซลสีขาวต่อเนื่องหลังจากพิกเซลสีดำต่อเนื่อง แล้วเราต้องการหาความกว้างสูงสุดของพิกเซลสีขาว โดยการค้นหาแนวตั้งไซต์ทั้งซ้าย และขวา แล้ว ถ้าความกว้างใหม่ เล็กกว่าครึ่งของความกว้างสูงสุดก่อนหน้านี้ แล้วเราแบ่งการสแกนเนื่องจากถ้าเราเข้าคิ้ว แล้วสถานการณ์นี้จะเกิดขึ้น แล้วเราตัดหน้าจากตำแหน่งเริ่มต้นของหน้าผาก และจะ 1.5 ของความกว้างคูณความสูงรูปภาพ-11รูปภาพ PNG-12PNGในภาพ X จะเท่ากับความกว้างสูงสุดของหน้าผาก แล้ว เราจะมีรูปภาพซึ่งจะประกอบด้วยเฉพาะตา จมูก และลิ แล้ว เราจะตัดภาพ RGB ตามรูปแบบไบนารีตรวจตาตรวจตา เราแปลงหน้าเปลี่ยนไปหน้าไบนารี ตอนนี้ เราพิจารณาความกว้างของใบหน้า โดย W. เราสแกนจาก W/4 (W-W/4) หาตำแหน่งกึ่งกลางของตาทั้งสอง เซลสีขาวต่อเนื่องสูงตามความสูงระหว่างช่วงเป็นตำแหน่งกึ่งกลางของตาทั้งสองรูปภาพ-13PNGแล้ว เราหาตำแหน่งเริ่มต้นสูง หรือบนคิ้วสองโดยค้นหาแนวตั้ง สำหรับตาซ้าย เราค้นหา w/8 ไปกลาง และสำหรับตาขวา เราค้นกลางกับ w-w/8 นี่ w คือ ความกว้าง ของรูป และกลางคือ ตำแหน่งกึ่งกลางของตาทั้งสอง อาจมีบางพิกเซลสีขาวระหว่างคิ้วและตา จะทำให้คิ้วและตาเชื่อม เราทำบางอย่างต่อเนื่องดำพิกเซลในแนวตั้งจากคิ้วตา สำหรับตาซ้าย บรรทัดแนวตั้งสีดำพิกเซลอยู่ในระหว่าง กลาง/2 กลาง/4 และตาขวาที่บรรทัดอยู่ระหว่าง mid+(w-mid) / 4 ไป mid+3*(w-mid) 4 และความสูงของเซลเส้นสีดำได้จากคิ้วที่เริ่มต้นความสูง (h-คิ้วเริ่มต้นตำแหน่ง) / 4 ที่นี่ w คือ ความกว้างของรูปภาพ และกลางคือ ตำแหน่งกึ่งกลางของตาทั้งสอง และ h คือ ความสูงของภาพ แล้ว เราหาตำแหน่งล่างของตาสอง โดยค้นหาพิกเซลสีดำในแนวตั้ง สำหรับตาซ้าย เราค้นหาตัว กลาง/4 กลาง - กลาง/4 ความกว้าง และสำหรับตาขวา เราค้นกลาง + (w-กลาง) / 4 เป็นกลาง + 3 *(w-mid) / 4 ความกว้างจากภาพล่างสุดเพื่อเริ่มต้นตำแหน่งของคิ้ว แล้ว เราพบตาซ้ายขวา โดยการค้นหาพิกเซลสีดำจากตำแหน่งกลางในแนวนอนไปยังตำแหน่งเริ่มต้นของพิกเซลสีดำระหว่างตำแหน่งบนและล่างตำแหน่งของตาซ้าย และด้านซ้ายข้างในตาขวาเราค้นหากลางไปยังตำแหน่งเริ่มต้นของพิกเซลสีดำระหว่างตำแหน่งบนและล่างตำแหน่งของตาขวา ความกว้างเริ่มต้นของรูปคือด้านซ้ายของตาซ้าย และขวาของตาขวาคือ ความกว้างที่สิ้นสุดของรูป แล้ว เราตัดตำแหน่งบน ล่างตำแหน่ง ด้านซ้ายด้านข้างและด้านขวาของตาสองจากภาพ RGBpic-14.PNGLip DetectionFor lip detection, we determine the lip box. And we consider that lip must be inside the lip box. So, first we determine the distance between the forehead and eyes. Then we add the distance with the lower height of the eye to determine the upper height of the box which will contain the lip. Now, the starting point of the box will be the ¼ position of the left eye box and ending point will be the ¾ position of the right eye box. And the ending height of the box will be the lower end of the face image. So, this box will contain only lip and may some part of the nose. Then we will cut the RGB image according the box.pic-15.PNGSo, for detection eyes and lip, we only need to convert binary image from RGB image and some searching among the binary image.pic-16.PNGApply Bezier Curve on LipIn the lip box, there is lip and may be some part of nose. So, around the box there is skin color or the skin. So, we convert the skin pixel to white pixel and other pixel as black. We also find those pixels which are similar to skin pixels and convert them to white pixel. Here, if two pixels RGB values difference is less than or equal 10, then we called them similar pixel. Here, we use histogram for finding the distance between the lower average RGB value and higher average RGB value. If the distance is less than 70, then we use 7 for finding similar pixel and if the distance is getter than or equal 70 then we use 10 for finding similar pixel. So, the value for finding similar pixel depends on the quality of the image. If the image quality is high, we use 7 for finding similar pixel and if the image quality is low, we use 10.pic-17.PNGSo, in the binary image, there are black regions on lip, nose and may some other little part which have a little different than skin color. Then we apply big connected region for finding the black region which contain lip in binary image. And we are sure that the big connected region is the lip because in the lip box, lip is the largest thing which is different than skin.pic-18.PNGThen we have to apply Bezier curve on the binary lip. For apply Bezier curve, we find the starting and ending pixel of the lip in horizontal. Then we draw two tangents on upper lip from the starting and ending pixel and also find two points on the tangent which is not the part of the lip. For the lower lip, we find two point similar process of the upper lip. We use Cubic Bezier curves for draw the Bezier curve of the lip. We draw two Bezier curve for the lip, one for upper lip and one for lower lip.
pic-19.PNG
Apply Bezier Curve on Eye
For apply Bezier curve on eyes, first we have to remove eyebrow from eye. For remove eyebrow, we search 1st continuous black pixel then continuous white pixel and then continuous black pixel from the binary image of the eye box. Then we remove the 1st continuous black pixel from the box and then we get the box which only contains the eye.
pic-20.PNG pic-21.PNG
Now, the eye box which contains only eye, has some skin or skin color around the box. So, we apply similar skin color like the lip for finding the region of eye. Then we apply big connect for finding the highest connected region and this is the eye because in the eye box, eye is the biggest thing which is not similar to the skin color.
pic-22.PNG pic-23.PNG
Then we apply the Bezier curve on the eye box, similar to the lip. Then we get the shape of the eye.
pic-24.PNG
Database and Training
In our database, there are two tables. One table “Person” is for storing the name of people and their index of 4 kinds of emotion which are stored in other table “Position”. In the “Position” table, for each index, there are 6 control points for lip Bezier curve, 6 control points for left eye Bezier curve, 6 control points for right eye Bezier curve, lip height and width, left eye height and width and right eye height and width. So, by this method, the program learns the emotion of the people.
pic-25.PNG
Emotion Detection
For emotion detection of an image, we have to find the Bezier curve of the lip, left eye and right eye. Then we convert each width of the Bezier curve to 100 and height according to its width. If the person’s emotion information is available in the database, then the program will match which emotion’s height is nearest the current height and the program will give the nearest emotion as output.
pic-26.PNG
If the person’s emotion information is not available in the database, then the program calculates the average height for each emotion in the database for all people and then get a decision according to the average height.
pic-27.PNG
การแปล กรุณารอสักครู่..
