/*******************************
作者:David Bao
时间:2012年3月15日
描述:
利用matlab中的PCA程序,将30张图片进行合成一个大矩阵,进行pca操作后,得到一个大矩阵,每一行为每幅图的pca特征
6种表情{angry,disgust,fear,sadness,smile,surprise}
每种表情5个图片
共30副
此程序专门针对train集!
矩阵大小为:30*200 导入成为arff格式
功能:将PCA得出的文本数据转成weka所需的arff格式
********************************/
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
void main()
{
string FileName;
char name[30];
fstream InFile;
ofstream OutFile("C:\\Users\\user\\Desktop\\MyDoc\\ExpressionData\\JAFFE\\Gabor-PCA\\20120518\\down\\Gabor-PCA_train-Down.arff");
if(OutFile.is_open())
{
OutFile<<"@relation 'FER'"<<endl;
char *ch = new char;
for(int i=1;i<=300;i++)
{
itoa(i,ch,10);
OutFile<<"@attribute feature"+string(ch)+" real"<<endl;
}
OutFile << "@attribute 'class' {angry,disgust,fear,happy,neutral,sad,surprise}"<<endl;
OutFile << "@data" << endl;
FileName = string("C:\\Users\\user\\Desktop\\MyDoc\\ExpressionData\\JAFFE\\Gabor-PCA\\20120518\\TXT\\Gabor-PCA-train-Down.txt");
cout << FileName.c_str() <<endl;
InFile.open(FileName.c_str(),ios::in);
string line;
int i=1;
while(getline(InFile,line))
{
istringstream stream(line);
string word;
while(stream >> word)
{
OutFile << word.c_str() << ",";
}
//JAFFE Database
if(i>=1 && i<= 20)
{
OutFile << "angry" <<endl;
}
if(i>=21 && i<= 40)
{
OutFile << "disgust" <<endl;
}
if(i>=41 && i<= 60)
{
OutFile << "fear" <<endl;
}
if(i>=61 && i<= 80)
{
OutFile << "happy" <<endl;
}
if(i>=81 && i<= 100)
{
OutFile << "neutral" <<endl;
}
if(i>=101 && i<= 120)
{
OutFile << "sad" <<endl;
}
if(i>=121 && i<= 140)
{
OutFile << "surprise" <<endl;
}
//CMU database
//switch(i)
//{
//case 1:
//case 2:
//case 3:
//case 4:
//case 5:
// OutFile << "angry"<<endl;
// break;
//case 6:
//case 7:
//case 8:
//case 9:
//case 10:
// OutFile << "disgust"<<endl;
// break;
//case 11:
//case 12:
//case 13:
//case 14:
//case 15:
// OutFile << "fear"<<endl;
// break;
//case 16:
//case 17:
//case 18:
//case 19:
//case 20:
// OutFile << "sadness"<<endl;
// break;
//case 21:
//case 22:
//case 23:
//case 24:
//case 25:
// OutFile << "smile"<<endl;
// break;
//case 26:
//case 27:
//case 28:
//case 29:
//case 30:
// OutFile << "surprise"<<endl;
// break;
//}
i++;
}
}
else
{
cout << "打开文件失败哇……" <<endl;
}
InFile.close();
OutFile.close();
}
做过的东西一定要好好的保留下来,说不定哪天还会用上,上次就没有细心整理,害的这次导师说修改方案,获取另外的特征数据,结果我要重新写一遍,以上程序用来进行格式转换,两个表情库:CMU和JAFFE。两个数据库选取的图片个数不一样,所以以上程序中注释的那段是用来处理CMU表情库的,上面紧跟着的是用来处理JAFFE表情库的
本程序针对训练集
CMU表情库:30幅训练图片=6种表情*5张图片
JAFFE表情库:140训练图片=7种表情*20张图片