資源簡介
PCA+KNN人臉表情識別,完整工程項目,親測可用。開發工具vs2013,opencv2.4.9
代碼片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//using?namespace?face;
using?namespace?cv;
using?namespace?std;
void?getVectorFileName(string?imgPath?string?txtPath)
{
Directory?dir;
string?exten1?=?“*“;//“*“??
bool?addPath1?=?false;//true;??
ofstream?fout;
fout.open(txtPath?ofstream::app);
vector?filenames?=?dir.GetListFiles(imgPath?exten1?addPath1);
cout?<“file?names:?“?< for?(int?i?=?0;?i?
cout?< fout?<
}
}
void?main(){
////?讀入一張圖片(游戲原畫)??
//string?path?=?“image/jaffe/KA/KA_1.jpg“;
//Mat?img?=?imread(path);
////?創建一個名為?“游戲原畫“窗口??
//namedWindow(“游戲原畫“);
////?在窗口中顯示游戲原畫??
//imshow(“游戲原畫“?img);
////?等待6000?ms后窗口自動關閉??
//waitKey(6000);
string?path0?=?“D:\\workSation\\VisualStudio2013\\opencv\\opencv\\uitls_xml\\haarcascade_frontalface_default.xml“;
CascadeClassifier?cas(path0);????//加載人臉分類器
Ptr?fc?=?createFisherFaceRecognizer();
CascadeClassifier?face_detect;
String?path1?=?“D:\\workSation\\VisualStudio2013\\opencv\\opencv\\uitls_xml\\haarcascade_frontalface_alt.xml“;
bool?flag?=?face_detect.load(path1);
if?(!flag){
cout?<“出錯了“?< system(“pause“);
}
vector?images;
vectorlabels;
string?str[7]?=?{?“Anger““Disgust““Fear““Happiness““Neutral““Sadness““Surprise“};
string?temp?filenName;
//cout?<length?< for?(int?i?=?0;?i?7;?i++){
string?txtPath?=?“txtFile/“?+?str[i]?+?“.txt“;
string?imgPath?=?“image/jaffe/“?+?str[i];
getVectorFileName(imgPath?txtPath);
ifstream?myfile(txtPath);
cout?<“txtPath?=?“<
if?(!myfile.is_open())
{
cout?<“未成功打開文件“?< system(“pause“);
}
while?(getline(myfile?filenName))
{
temp?=?imgPath+?“/“?+?filenName;
cout?<“?filePath“?< Mat?a1?=?imread(temp?CV_LOAD_IMAGE_GRAYSCALE);
images.push_back(a1);
labels.push_back(i);
////?創建一個名為?“游戲原畫“窗口??
//namedWindow(“游戲原畫“);
////?在窗口中顯示游戲原畫??
//imshow(“游戲原畫“?a1);
//waitKey(1000);
/*cout?<“namedWindow成功打開文件“?< }
myfile.close();
}
cout?<
fc->train(images?labels);????//訓練
fc->save(“FisherFace.xml“);
/* waitKey()*/;
VideoCapture?cap(0);
if?(!cap.isOpened())
{
cout?<“攝像頭打開失敗“?< }
Mat?image;
vector?recs;
Mat?test(256?256?CV_8UC1);
Mat?gray;
int?x?=?0?y?=?0;
for?(;;)
{
cap?>>?image;
if?(image.empty())
break;
cas.detectMultiScale(image?recs?1.2?6?0?Size(50?50));????//先檢測人臉
for?(int?i?=?0;?i? {
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-03-08?16:04??opencv\
?????目錄???????????0??2017-10-30?10:19??opencv\Debug\
?????文件??????246784??2017-11-08?11:39??opencv\Debug\opencv.exe
?????文件?????1497176??2017-11-08?11:39??opencv\Debug\opencv.ilk
?????文件?????3207168??2017-11-08?11:39??opencv\Debug\opencv.pdb
?????目錄???????????0??2017-10-20?16:42??opencv\gabor\
?????文件????????1386??2017-02-25?12:09??opencv\gabor\anger_1.jpg
?????文件????????1373??2017-02-25?12:09??opencv\gabor\anger_2.jpg
?????文件????????1451??2017-02-25?12:09??opencv\gabor\anger_3.jpg
?????文件????????1423??2017-02-25?12:09??opencv\gabor\anger_4.jpg
?????文件????????1579??2017-02-25?12:09??opencv\gabor\anger_5.jpg
?????文件????????1557??2017-02-25?12:09??opencv\gabor\anger_6.jpg
?????文件????????1389??2017-02-25?12:09??opencv\gabor\disgust_1.jpg
?????文件????????1395??2017-02-25?12:09??opencv\gabor\disgust_2.jpg
?????文件????????1474??2017-02-25?12:09??opencv\gabor\disgust_3.jpg
?????文件????????1479??2017-02-25?12:09??opencv\gabor\disgust_4.jpg
?????文件????????1533??2017-02-25?12:09??opencv\gabor\disgust_5.jpg
?????文件????????1533??2017-02-25?12:09??opencv\gabor\disgust_6.jpg
?????文件????????1559??2017-02-25?12:09??opencv\gabor\fear_1.jpg
?????文件????????1557??2017-02-25?12:09??opencv\gabor\fear_2.jpg
?????文件????????1383??2017-02-25?12:09??opencv\gabor\fear_3.jpg
?????文件????????1363??2017-02-25?12:09??opencv\gabor\fear_4.jpg
?????文件????????1463??2017-02-25?12:09??opencv\gabor\fear_5.jpg
?????文件????????1473??2017-02-25?12:09??opencv\gabor\fear_6.jpg
?????文件????????1368??2017-02-25?12:09??opencv\gabor\happiness_1.jpg
?????文件????????1349??2017-02-25?12:09??opencv\gabor\happiness_2.jpg
?????文件????????1531??2017-02-25?12:09??opencv\gabor\happiness_3.jpg
?????文件????????1533??2017-02-25?12:09??opencv\gabor\happiness_4.jpg
?????文件????????1508??2017-02-25?12:09??opencv\gabor\happiness_5.jpg
?????文件????????1523??2017-02-25?12:09??opencv\gabor\happiness_6.jpg
?????文件????????1594??2017-02-25?12:09??opencv\gabor\sadness_1.jpg
............此處省略363個文件信息
- 上一篇:AVOD論文講解PPT
- 下一篇:算法藝術與信息學競賽pdf以及配套課件
評論
共有 條評論