www.pudn.com > PCA_faceRec_V2.rar > detction.cpp
#include "HaarDetecting.h"
bool read_Bigphoto_name(const char * s,int& PhotoNum,string Bigphoto_name[])
{
WIN32_FIND_DATA fd;
HANDLE hFind;
CListm_filelist;
hFind=::FindFirstFile(s,&fd);
assert(!(hFind==INVALID_HANDLE_VALUE));
int count=0;
do
{
m_filelist.AddTail(CString(fd.cFileName));
count++;
} while(::FindNextFile(hFind,&fd));
::FindClose(hFind);
POSITION pos=m_filelist.GetHeadPosition();
CString strFile;
int i=0;
while (pos)
{
strFile=m_filelist.GetNext(pos);
Bigphoto_name[i]=strFile;
printf("%s ",strFile);
i++;
}
PhotoNum=i;
return true;
}
int main()
{
MySize origWindowSize;
origWindowSize.height=20; //最初的采样窗大小
origWindowSize.width=20; //
const int maxstep=14; //最大步长
const char* directory="DATA_1号用20000个\\";
string ss="检测出的人脸\\";
ClassifierCascade* cascade=NULL; //
DetCascadeClassifier* detcascade=NULL; //
int nImgWidth=1840,nImgHeight=1060; // ??
const char* s="temp\\0.bmp";
string s2="temp\\";
int PhotoNum;
string Bigphoto_name[100];
read_Bigphoto_name(s,PhotoNum,Bigphoto_name);
//for debug
//printf("PhotoNum: %d Bigphoto_name: %c\n",PhotoNum,Bigphoto_name[0]); //zou
//
cascade=LoadClassifierCascade(directory, maxstep, origWindowSize);
if (cascade==NULL)
{
cout<<"can not load the data for ClassifierCascade\n";
}
MyRect detRegion;
vector* vecFaces=new vector;
MySize min_size,max_size;
int min_neighbors=2;
double scale_factor=1.1F;
int liite_face_count=0;
string ww=".bmp",bb,dd;
int c=0;
int x,y,w,h;
BYTE* pb=NULL;
int temp_nImgWidth=0,temp_nImgHeight=0;
for(int k=0;kmax_size.height)
{
max_size.width=max_size.height;
}
else
max_size.height=max_size.width;
temp_nImgHeight=nImgHeight;
temp_nImgWidth=nImgWidth;
} //
clock_t start, finish;
double duration;start = clock();
HaarDetectFaces( pbyteSrcImg,
nImgWidth,nImgHeight,
detRegion,
detcascade,
vecFaces,
min_size,
max_size,
min_neighbors,
scale_factor );
vector::iterator iter_begin = vecFaces->begin();
vector::iterator iter_end = vecFaces->end();
vector::iterator iter_p;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
bb=Bigphoto_name[liite_face_count++];
int pos=bb.length()-4;
int i=0;
for (iter_p=iter_begin;iter_px;y=iter_p->y;w=iter_p->width;h=iter_p->height;
i++;
if(i>=1)
{
if(i==1)bb=bb.insert(pos,"_");
pos=bb.length()-4;
string c[5]={"a","b","c","d","e"};
if(i>1){
pos=bb.length()-4;
bb=bb.erase(pos-1,1);
}
pos=bb.length()-4;
bb=bb.insert(pos,c[i-1]);
dd=ss+bb;
printf("%s ",bb.c_str());
}
WriteBmpFile(dd.c_str(),pbyteSrcImg,w,h,nImgWidth,nImgHeight,x,y);
}
printf( "%.4f seconds\n", duration );
// bb=Bigphoto_name[liite_face_count++];
//bb=ss+bb;
// printf("nImgWidth=%d,nImgHeight=%d\n",nImgWidth,nImgHeight);
// WriteBmpFile(bb.c_str(),pbyteSrcImg,nImgWidth,nImgHeight); //写bmp文件(人脸检测结果)
//WriteBmpFile(bb.c_str(),pbyteSrcImg,w+15,h+15,nImgWidth,nImgHeight,x-15,y-15);
delete []pbyteSrcImg;
}
ReleaseClassifierCascade( cascade);
return 0;
}