爱玩科技网
您的当前位置:首页detection

detection

来源:爱玩科技网
#include \"HaarDetecting.h\"

将HaarDetecting.h的全部内容复制插入到#include \"HaarDetecting.h\"命令处 bool read_Bigphoto_name(const char * s,int& PhotoNum,string Bigphoto_name[])

Boolean(布尔)数据在C++中使用内置类型bool表示。bool类型的变量只可能有两个值true或false,在现实世界中它用于表示“是”或“否”、“高”或“低”等这种只有两个状态的事物再自然不过。例如用于表示检测某年是否润年的函数,其返回值类型显示只有两种情况“是”或“否”,如代码1 -1所示。 // 代码 1-1

bool IsLeapYear( const unsigned int year) {

return (year % 4==0 && year % 100 !=0) || (year %400 ==0); }

这样用一个bool型变量来表示该函数的返回值,看起来非常自然。而在C语言(C99之前,而且目前很多编译器没有完整实现C99)中没有内置boolean类型,只能使用宏、typedef、enum等手段模拟出bool类型来,如代码1-2使用enum模拟。 // 代码 1-2

typedef enum { false = 0, true = 1 }bool;

有了这样的定义,使得在C语言的编译器中代码1-1中的代码也是可以编译的,而在Windows的API中则使用typedef了宏定义了一种类型BOOL,其实实现了与bool同样的效果。 // 代码1-3

typedef int BOOL; #ifndef FALSE #define FALSE 0 #endif

#ifndef TRUE #define TRUE 1 #endif

没有统一的布尔类型在大型的工程项中特别是用到第三方程序库时,可能使用不同的手段模拟布尔类型以提交代码的可读性,这样会使得代码有些混乱。C++引入了bool内置类型,解决了代码的一致性问题。

{

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 \ i++; } PhotoNum=i; return true; }

int main() { MySize origWindowSize; origWindowSize.height=20; origWindowSize.width=20; const int maxstep=14; const char* directory=\"E:\\\\人脸检测\\\\haardetction2\\\\DATA_1号用20000个\\\\\"; string ss=\"E:\\\\人脸检测\\\\haardetction2\\\\检测出的人脸\\\\\"; ClassifierCascade* cascade=NULL; DetCascadeClassifier* detcascade=NULL; int nImgWidth=1840,nImgHeight=1060; const char* s=\"E:\\\\人脸检测\\\\haardetction2\\\emp\\\\*.bmp\"; string s2=\"E:\\\\人脸检测\\\\haardetction2\\\emp\\\\\"; int PhotoNum; string Bigphoto_name[100]; //将256色位图读入Bigphoto_name;

read_Bigphoto_name(s,PhotoNum,Bigphoto_name); //载入分类器,将每一个弱分类器载入到了 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.3F;

int liite_face_count=0; string ww=\".bmp\ int c=0; int x,y,w,h;

BYTE* pb=NULL;

int temp_nImgWidth=0,temp_nImgHeight=0; //处理每张照片 PhotoNum 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; for (iter_p=iter_begin;iter_px;y=iter_p->y;w=iter_p->width;h=iter_p->height; for (int i=0;iduration = (double)(finish - start) / CLOCKS_PER_SEC; printf( \"%.4f seconds\\n\ bb=Bigphoto_name[liite_face_count++]; bb=ss+bb; WriteBmpFile(bb.c_str(),pbyteSrcImg,nImgWidth,nImgHeight);

}

delete []pbyteSrcImg; }

ReleaseClassifierCascade( cascade);

return 0;

因篇幅问题不能全部显示,请点此查看更多更全内容