資源簡(jiǎn)介
我的環(huán)境是opencv2.4.13,環(huán)境是VS2013,經(jīng)過(guò)訓(xùn)練xml文件實(shí)現(xiàn)人臉sad,smile,surprise表情識(shí)別,直接打開(kāi)就可以使用。
代碼片段和文件信息
//opencv2.4.9?+?vs2012?+?64位
#include?
#include?
#include?
#include?
using?namespace?cv;
using?namespace?std;
char*?WcharToChar(const?wchar_t*?wp)
{
char?*m_char;
int?len?=?WideCharToMultiByte(CP_ACP?0?wp?wcslen(wp)?NULL?0?NULL?NULL);
m_char?=?new?char[len?+?1];
WideCharToMultiByte(CP_ACP?0?wp?wcslen(wp)?m_char?len?NULL?NULL);
m_char[len]?=?‘\0‘;
return?m_char;
}
wchar_t*?CharToWchar(const?char*?c)
{
wchar_t?*m_wchar;
int?len?=?MultiByteToWideChar(CP_ACP?0?c?strlen(c)?NULL?0);
m_wchar?=?new?wchar_t[len?+?1];
MultiByteToWideChar(CP_ACP?0?c?strlen(c)?m_wchar?len);
m_wchar[len]?=?‘\0‘;
return?m_wchar;
}
wchar_t*?StringToWchar(const?string&?s)
{
const?char*?p?=?s.c_str();
return?CharToWchar(p);
}
String?facename?=?“haarcascade_frontalface_alt.xml“;
CascadeClassifier?facecas;
RNG?rng(12345);
Mat?src;
/*nt?main(){
Mat?gray;
VideoCapture?capture;
capture.open(0);
if?(capture.isOpened()){
while?(1){
capture?>>?src;
//src?=?imread(“D:\\a\\face0.jpg“);
if?(!src.empty()){
cvtColor(src?gray?CV_BGR2GRAY);
equalizeHist(gray?gray);
deletelbp(gray);
//deletebody(gray);
/*deleteall(gray);
deleteface(gray);
deleteeye(gray);
deletemouth(gray);
deletenose(gray);
deletesmile(gray);
imshow(“【檢測(cè)】“?src);
}
int?c?=?waitKey(30);
if?((char)c?==?‘c‘)
break;
}
}
}
*/
vector?deletelbp(Mat?frame);
int?main()
{
const?string?fileform?=?“*.png“;
const?string?perfileReadPath?=?“charSamples“;
const?int?sample_mun_perclass?=?50;//訓(xùn)練字符每類數(shù)量
const?int?class_mun?=?3;//訓(xùn)練字符類數(shù)
const?int?image_cols?=?24;
const?int?image_rows?=?24;
string??fileReadName
fileReadPath;
char?temp[256];
float?trainingData[class_mun*sample_mun_perclass][image_rows*image_cols]?=?{?{?0?}?};//每一行一個(gè)訓(xùn)練樣本
float?labels[class_mun*sample_mun_perclass][class_mun]?=?{?{?0?}?};//訓(xùn)練樣本標(biāo)簽
for?(int?i?=?0;?i?<=?class_mun?-?1;?++i)//不同類
{
//讀取每個(gè)類文件夾下所有圖像
int?j?=?0;//每一類讀取圖像個(gè)數(shù)計(jì)數(shù)
sprintf_s(temp?“%d“?i);
fileReadPath?=?perfileReadPath?+?“/“?+?temp?+?“/“?+?fileform;
cout?<“文件夾“?<
// system(“pause“);
HANDLE?hFile;
LPCTSTR?lpFileName?=?StringToWchar(fileReadPath);//指定搜索目錄和文件類型,如搜索d盤的音頻文件可以是“D:\\*.mp3“
WIN32_FIND_DATA?pNextInfo;??//搜索得到的文件信息將儲(chǔ)存在pNextInfo中;
hFile?=?FindFirstFile(lpFileName?&pNextInfo);//請(qǐng)注意是?&pNextInfo??不是?pNextInfo;
if?(hFile?==?INVALID_HANDLE_VALUE)
{
exit(-1);//搜索失敗
}
//do-while循環(huán)讀取
do
{
if?(pNextInfo.cFileName[0]?==?‘.‘)//過(guò)濾.和..
continue;
j++;//讀取一張圖
//wcout< printf(“%s\n“?WcharToChar(pNextInfo.cFileName));
//對(duì)讀入的圖片進(jìn)行處理
Mat?srcImage?=?imread(perfileReadPath?+?“/“?+?temp?+?“/“?+?WcharToChar(pNextInfo.cFileName)?CV_LOAD_IMAGE_GRAYSCALE);
Mat?resizeImage;
Mat?trainImage;
Mat?result;
resize(srcImage?resizeImage?Size(image_c
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????3031486??2017-01-26?14:44??其他\bpcharModel.xm
?????文件?????151040??2017-01-26?14:43??其他\Debug\其他.exe
?????文件?????914968??2017-01-26?14:43??其他\Debug\其他.ilk
?????文件????2633728??2017-01-26?14:43??其他\Debug\其他.pdb
?????文件???????1535??2017-01-22?20:28??其他\其他\charSamples\0\11.png
?????文件???????1559??2017-01-22?20:28??其他\其他\charSamples\0\110.png
?????文件???????1544??2017-01-22?20:28??其他\其他\charSamples\0\1100.png
?????文件???????1574??2017-01-22?20:28??其他\其他\charSamples\0\1101.png
?????文件???????1573??2017-01-22?20:28??其他\其他\charSamples\0\1102.png
?????文件???????1549??2017-01-22?20:28??其他\其他\charSamples\0\1103.png
?????文件???????1547??2017-01-22?20:28??其他\其他\charSamples\0\1104.png
?????文件???????1599??2017-01-22?20:28??其他\其他\charSamples\0\1105.png
?????文件???????1579??2017-01-22?20:28??其他\其他\charSamples\0\1106.png
?????文件???????1602??2017-01-22?20:28??其他\其他\charSamples\0\1107.png
?????文件???????1619??2017-01-22?20:28??其他\其他\charSamples\0\1108.png
?????文件???????1602??2017-01-22?20:28??其他\其他\charSamples\0\1109.png
?????文件???????1545??2017-01-22?20:28??其他\其他\charSamples\0\111.png
?????文件???????1592??2017-01-22?20:28??其他\其他\charSamples\0\1110.png
?????文件???????1613??2017-01-22?20:28??其他\其他\charSamples\0\1111.png
?????文件???????1592??2017-01-22?20:28??其他\其他\charSamples\0\1112.png
?????文件???????1621??2017-01-22?20:28??其他\其他\charSamples\0\1113.png
?????文件???????1500??2017-01-22?20:28??其他\其他\charSamples\0\1114.png
?????文件???????1499??2017-01-22?20:28??其他\其他\charSamples\0\1115.png
?????文件???????1502??2017-01-22?20:28??其他\其他\charSamples\0\1116.png
?????文件???????1516??2017-01-22?20:28??其他\其他\charSamples\0\1117.png
?????文件???????1508??2017-01-22?20:28??其他\其他\charSamples\0\1118.png
?????文件???????1515??2017-01-22?20:28??其他\其他\charSamples\0\1119.png
?????文件???????1537??2017-01-22?20:28??其他\其他\charSamples\0\112.png
?????文件???????1478??2017-01-22?20:28??其他\其他\charSamples\0\1120.png
?????文件???????1486??2017-01-22?20:28??其他\其他\charSamples\0\1121.png
............此處省略462個(gè)文件信息
評(píng)論
共有 條評(píng)論