表情识别--JAFFE数据集1

标签: 表情识别 jaffe数据集
47人阅读 评论(2) 收藏 举报
分类:

JAFFE数据集一共有213张图像.选取了10名日本女学生,每个人做出7种表情.7种表情包括: Angry,Disgust,Fear,Happy,Sad,Surprise,Neutral.(愤怒,厌恶,恐惧,高兴,悲伤,惊讶,中性)

裁剪保存人脸

将人脸区域裁剪出,去除多余干扰,然后将获得的人脸区域缩放为48*48大小的图像,存储为.csv格式数据.

#!/usr/bin/python
# coding:utf8

import cv2
import os
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import csv

def detect(img, cascade):
    rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),flags=cv2.CASCADE_SCALE_IMAGE)
    if len(rects) == 0:
        return []
    rects[:, 2:] += rects[:, :2]
    return rects

cascade = cv2.CascadeClassifier("/home/.../data/haarcascades/haarcascade_frontalface_alt.xml")

f = "/home/w/mycode/jaffe/"
fs = os.listdir(f)
data = np.zeros([213, 48*48], dtype=np.uint8)
label = np.zeros([213], dtype=int)
i = 0
for f1 in fs:
    tmp_path = os.path.join(f, f1)
    if not os.path.isdir(tmp_path):
        # print(tmp_path[len(f):])
        img = cv2.imread(tmp_path, 1)
        dst = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        rects = detect(dst, cascade)
        for x1, y1, x2, y2 in rects:
            cv2.rectangle(img,(x1+10,y1+20),(x2-10,y2),(0,255,255),2)
            # 调整截取脸部区域大小
            img_roi = np.uint8([y2-(y1+20), (x2-10)-(x1+10)])
            roi = dst[y1+20:y2, x1+10:x2-10]
            img_roi = roi
            re_roi = cv2.resize(img_roi, (48,48))
            # 获得表情label
            img_label = tmp_path[len(f)+3:len(f)+5]
            # print(img_label)
            if img_label == 'AN':
                label[i] = 0
            elif img_label == 'DI':
                label[i] = 1
            elif img_label == 'FE':
                label[i] = 2
            elif img_label == 'HA':
                label[i] = 3
            elif img_label == 'SA':
                label[i] = 4
            elif img_label == 'SU':
                label[i] = 5
            elif img_label == 'NE':
                label[i] = 6
            else:
                print("get label error.......\n")

            data[i][0:48*48] = np.ndarray.flatten(re_roi)
            i = i + 1

            # cv2.imshow("src", dst)
            # cv2.imshow("img", img)
            # if cv2.waitKey() == 32:
            #     continue

with open(r"/home/.../face.csv","w") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(['emotion', 'pixels'])
    for i in range(len(label)):
        data_list = list(data[i])
        b = " ".join(str(x) for x in data_list)
        l = np.hstack([label[i], b])
        writer.writerow(l)

裁剪人脸的区域:
这里写图片描述

查看保存的表情数据

从保存的face.csv中查看保存的表情数据:

#!/usr/bin/python
# coding:utf8

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd


emotion ={0:'Angry',1:'Disgust',2:'Fear',3:'Happy',4:'Sad',5:'Surprise',6:'Neutral'}

data = pd.read_csv(r'/home/.../face.csv', dtype='a')
label = np.array(data['emotion'])
img_data = np.array(data['pixels'])

N_sample = label.size
Face_data = np.zeros((N_sample, 48*48))
Face_label = np.zeros((N_sample, 7), dtype=int)
# # 显示人脸以及对应表情
for i in range(25):
    x = img_data[i]
    x = np.fromstring(x, dtype=float, sep=' ')
    x = x/x.max()
    img_x = np.reshape(x, (48, 48))
    plt.subplot(5,5,i+1)
    plt.axis('off')
    plt.title(emotion[int(label[i])])
    plt.imshow(img_x, plt.cm.gray)
plt.show()

输出:

这里写图片描述

查看个部分数量

从保存的表情数据中查看个部分表情的数量.

#!/usr/bin/python
# coding:utf8

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

emotion ={0:'Angry',1:'Disgust',2:'Fear',3:'Happy',4:'Sad',5:'Surprise',6:'Neutral'}

data = pd.read_csv(r'/home/w/下载/face.csv', dtype='a')
label = np.array(data['emotion'])
img_data = np.array(data['pixels'])
N_sample = label.size

emotions = np.zeros(7)
for i in label:
    for j in range(7):
        if int(i) == j:
            emotions[j] = emotions[j] + 1

print(emotions)
plt.bar(range(7),emotions, 0.5, color= ['red','green','blue'])
plt.xlabel('emotions')
plt.xticks(range(7), ['Angry','Disgust','Fear','Happy','Sad','Surprise','Neutral'], rotation=0)
plt.ylabel('number')
plt.grid()
plt.show()

这里写图片描述


The Japanese Female Facial Expression (JAFFE) Database

查看评论

JAFFE人脸数据库介绍

日本ATR(Advanced Telecommunication Research InstituteInternational)的专门用于表情识别研究的基本表情数据库JAFFE,该数据库中包含了21...
  • yueguanyun
  • yueguanyun
  • 2013-01-21 17:33:34
  • 2757

表情识别--JAFFE数据集1

JAFFE数据集一共有213张图像.选取了10名日本女学生,每个人做出7种表情.7种表情包括: Angry,Disgust,Fear,Happy,Sad,Surprise,Neutral.(愤怒,厌恶...
  • akadiao
  • akadiao
  • 2018-04-16 10:44:00
  • 47

表情识别--JAFFE数据集3:keras训练CNN网络

在上上一篇表情识别–JAFFE数据集1中,将JAFFE数据集中的人脸区域获取,并转换为.csv文件存储.face.csv 使用keras建立多层CNN网络对表情数据进行训练. 网络结构为: &a...
  • akadiao
  • akadiao
  • 2018-04-21 11:33:56
  • 28

表情识别--JAFFE数据集

  • 2018年04月21日 10:57
  • 1.66MB
  • 下载

人脸表情识别常用的几个数据库

人脸表情识别
  • shinian1987
  • shinian1987
  • 2014-05-16 11:41:33
  • 17965

表情识别数据集整理

原文见http://blog.csdn.net/computerme/article/details/49469767 CK and CK+  It contains 97 subject...
  • liugallup
  • liugallup
  • 2016-05-22 20:59:20
  • 2366

识别库

http://www.seas.upenn.edu/~taskar/ocr/
  • cschengvdn3
  • cschengvdn3
  • 2014-09-29 09:05:46
  • 250

【深度学习】基于caffe的表情识别(二):数据集介绍及处理

《基于caffe的表情识别》系列文章索引:http://blog.csdn.net/pangyunsheng/article/details/79434263一、数据集介绍    在本实验中我采用的数...
  • pangyunsheng
  • pangyunsheng
  • 2018-03-04 03:34:09
  • 564

日本JAFFE表情库

JAFFE简介,官方下载地址,图片标记
  • mikedadong
  • mikedadong
  • 2015-07-20 14:54:25
  • 2973

机器学习之——简单表情识别

      自开学以来,我们导师就让我们研究在线视频教育下的微表情识别。上学期课程太多,一直没时间写微博,趁着现在做项目,正好借此机会回顾一下之前学的机器学习。      从研究的角度讲,表情识别是一...
  • yxdd1gbk
  • yxdd1gbk
  • 2018-04-02 16:21:02
  • 70
    个人资料
    持之以恒
    等级:
    访问量: 4万+
    积分: 2072
    排名: 2万+
    最新评论