文件处理_项目中用到_保存版
2012-05-20 08:08
267 查看
/******************************* 作者:David Bao 时间:2012年3月14日 描述: 6种表情{angry,disgust,fear,sadness,smile,surprise} 每种表情5个图片 每个图片Gabor变换出来6个图片 共180副 此程序专门针对train集! 功能:将PCA得出的文本数据转成weka所需的arff格式 ********************************/ #include <string> #include <stdlib.h> #include <stdio.h> #include <iostream> #include <fstream> #include <sstream> #define N 180 using namespace std; void main() { string FileName; char name[30]; fstream InFile; ofstream OutFile("D:\\train\\train.arff"); if(OutFile.is_open()) { OutFile<<"@relation 'FER'"<<endl; char *ch = new char; for(int i=1;i<=600;i++) { itoa(i,ch,10); OutFile<<"@attribute feature"+string(ch)+" real"<<endl; } OutFile << "@attribute 'class' {angry,disgust,fear,sadness,smile,surprise}"<<endl; OutFile << "@data" << endl; for(int i=1;i<=N;i++) { int counter = 0; //合成文件路径 itoa(i,name,10); FileName = string("C:\\Users\\user\\Desktop\\Gabor_PCA_train\\")+name; FileName += string(".txt"); cout << FileName.c_str() <<endl; string line; InFile.open(FileName.c_str(),ios::in); while(getline(InFile,line)) { istringstream stream(line); string word; while(stream >> word) { counter++; if(counter > 100) //此处乘以6,得到上面的维数 300,因为Gabor将1个图片弄出来了6个分图,而weka中的样本,每一行表示一幅图 { goto loop; } OutFile << word.c_str() << ","; } } loop: InFile.close(); if(i%6==0) { switch(i/6) { 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; } } } } else { cout << "打开文件失败哇……" <<endl; } //InFile.close(); OutFile.close(); system("pause"); }
相关文章推荐
- 文件处理_保留版_项目中用到
- 数组和字典的writeToFile方法——在项目开发中处理网络数据的时候,可以把请求获得的网络数据保存为plist文件,这样更方便开发
- 【python图像处理】tiff文件的保存与解析
- 第16周项目2-用文件保存学生名单
- C#新保存文件时候用到按日期时间命名的代码
- 遍历某路径的函数 ---- 将路径下 所有的文件保存在全局容器中,以待近一步处理
- 第14周项目2-用文件保存的学生名单
- web项目页面保存为word文件
- MVC项目开发中那些用到的知识点(将cshtml文件编译成dll文件)
- VS2010无法保存项目文件(.csprj)的问题解决方法
- 13周。。项目六成绩处理。。通过文件打开。。(4)
- php 文件上传 以及保存在本地的乱码问题处理
- 第14周项目2-用文件保存的学生名单
- 解决方案看起来是受源代码管理,但无法找到它的帮定信息.保存解决方案的源代码管理设置的MSSCCPRJ.SCC文件或其他项可能己被删除.由于无法自动恢复这些缺少的信息,缺少帮定的项目将被视为不受源代码管理.
- Web项目中 Tomcat 与 资源文件的一些处理
- 【数字图像处理】C++读取、旋转和保存bmp图像文件编程实现(转载)
- eclipse 在编译运行项目之前自动保存修改的文件
- 第十五周上机项目1 用二进制文件处理学生成绩
- 项目中用到的下载文件功能代码
- 项目里用到ibatis处理clob大对象的方法