/******************************************宏定义begin************************************************/
#define IMAGEWIDTH 32//图像宽度
#define IMAGEHEIGHT 32//图像高度
#define LENGTH 32//图像进行一维harr变换时的长度,相当于图像宽度和高度
//来自例程文件,说明哪些图片
#define MODEPHOTO00 1
#define MODEPHOTO01 2
#define MODEPHOTO02 3
#define MODEPHOTO03 4
#define MODEPHOTO04 5
#define MODEPHOTO05 6
#define MODEPHOTO06 7
#define MODEPHOTO07 8
#define MODEPHOTO10 9
#define MODEPHOTO11 10
#define MODEPHOTO12 11
#define MODEPHOTO13 12
#define MODEPHOTO14 13
#define MODEPHOTO15 14
#define MODEPHOTO16 15
#define MODEPHOTO17 16
#define MODEPHOTO20 17
#define MODEPHOTO21 18
#define MODEPHOTO22 19
#define MODEPHOTO23 20
#define MODEPHOTO24 21
#define MODEPHOTO25 22
#define MODEPHOTO26 23
#define MODEPHOTO27 24
#define MODEPHOTO30 25
#define MODEPHOTO31 26
#define MODEPHOTO32 27
#define MODEPHOTO33 28
#define MODEPHOTO34 29
#define MODEPHOTO35 30
#define MODEPHOTO36 31
#define MODEPHOTO37 32
#define MODEPHOTO40 33
#define MODEPHOTO41 34
#define MODEPHOTO42 35
#define MODEPHOTO43 36
#define MODEPHOTO44 37
#define MODEPHOTO45 38
#define MODEPHOTO46 39
#define MODEPHOTO47 40
//#define TESTMATRIX 101
#define TRAINPHOTO00 101
#define TRAINPHOTO01 102
#define TRAINPHOTO02 103
#define TRAINPHOTO10 104
#define TRAINPHOTO11 105
#define TRAINPHOTO12 106
#define TRAINPHOTO20 107
#define TRAINPHOTO21 108
#define TRAINPHOTO22 109
#define TRAINPHOTO30 110
#define TRAINPHOTO31 111
#define TRAINPHOTO32 112
#define TRAINPHOTO40 113
#define TRAINPHOTO41 114
#define TRAINPHOTO42 115
#define GRAYBARLEVEL 16
/******************************************宏定义end************************************************/
void InitImage(unsigned int nMode,unsigned char *pImage,int nWidth,int nHeight);
void conv(float* f,float* g,float* y,int length);
void haarone(float *input,float *output,int length);
void FloatImage(unsigned char *pImage,float *qImage,int nWidth,int nHeight);
void UcharImage(float *pImage,unsigned char *qImage,int nWidth,int nHeight);
void AddImage(float *pImage,int nWidth,int nHeight);
void CopyImage(float *pImage,float *qImage,int nWidth,int nHeight);
void MinImage(float *pImage,float *qImage,int nWidth,int nHeight);
void MaxImage(float *pImage,float *qImage,int nWidth,int nHeight);
unsigned int imageIndex[5][8];
unsigned int trainIndex[5][3];
unsigned char dbImage[IMAGEWIDTH*IMAGEHEIGHT];//输入图像
float outImage[IMAGEWIDTH][IMAGEHEIGHT];//输出图像
float changeImage[IMAGEWIDTH][IMAGEHEIGHT];//中间变量1
float nextImage[IMAGEWIDTH][IMAGEHEIGHT];//中间变量2
float endImage[IMAGEWIDTH/2][IMAGEHEIGHT/2];
int label[40]={1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5};
//unsigned char outcharImage[IMAGEWIDTH][IMAGEHEIGHT];//输出图像
//unsigned char changecharImage[IMAGEWIDTH][IMAGEHEIGHT];//中间变量1
//unsigned char nextcharImage[IMAGEWIDTH][IMAGEHEIGHT];//中间变量2
//定义所有图像的Harr特征数组
unsigned char endcharImage[40][IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char trainImage[15][IMAGEWIDTH/2][IMAGEHEIGHT/2];
/*
unsigned char endcharImage00[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage01[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage02[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage03[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage04[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage05[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage06[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage07[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage10[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage11[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage12[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage13[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage14[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage15[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage16[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage17[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage20[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage21[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage22[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage23[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage24[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage25[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage26[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage27[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage30[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage31[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage32[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage33[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage34[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage35[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage36[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage37[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage40[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage41[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage42[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage43[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage44[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage45[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage46[IMAGEWIDTH/2][IMAGEHEIGHT/2];
unsigned char endcharImage47[IMAGEWIDTH/2][IMAGEHEIGHT/2];
*/
float index[LENGTH];
float outdex[LENGTH];
int result[5][3];
int main()
{
int i,j,m,n;
int a,b;
int raw,col;//定义行和列变量
m=1;
n=101;
raw=IMAGEWIDTH;
col=IMAGEHEIGHT;
for(i=0;i<5;i++)
for(j=0;j<8;j++)
{
imageIndex[i][j]= m;
m++;
}//设置图像索引数组
for(a=0;a<5;a++)
for(b=0;b<8;b++)
{
InitImage(imageIndex[a][b],dbImage,IMAGEWIDTH,IMAGEHEIGHT);//读入图像
FloatImage(dbImage,*changeImage,IMAGEWIDTH,IMAGEHEIGHT);//强制转换为float型
for(i=0;i<col;i++)
{
for(j=0;j<raw;j++)
{
index[j]=changeImage[j][i];
}
haarone(index,outdex,LENGTH);
for(j=0;j<raw;j++)
{
changeImage[j][i]=outdex[j];
}
}//对所有列进行harr变换
for(i=0;i<raw;i++)
{
for(j=0;j<col;j++)
{
index[j]=changeImage[i][j];
}
haarone(index,outdex,LENGTH);
for(j=0;j<col;j++)
{
changeImage[i][j]=outdex[j];
}
}
//对图像进行归一化,经过归一化之后轨迹主要在左上角方格的右下角中,大小为32*32
MinImage(*changeImage,*nextImage,IMAGEWIDTH,IMAGEHEIGHT);
MaxImage(*nextImage,*outImage,IMAGEWIDTH,IMAGEHEIGHT);
//特征存入endImage数组中并输出
/*
AddImage(*changeImage,IMAGEWIDTH,IMAGEHEIGHT);
UcharImage(*changeImage,*changecharImage,IMAGEWIDTH,IMAGEHEIGHT);//强制转换为float型//对所有的行进行harr变化
UcharImage(*outImage,*outcharImage,IMAGEWIDTH,IMAGEHEIGHT);//强制转换为float型//对所有的行进行harr变化
*/
for(i=IMAGEHEIGHT/2;i<IMAGEHEIGHT;i++)
{
for(j=0;j<IMAGEWIDTH/2;j++)
{
endImage[i-IMAGEWIDTH/2][j]=outImage[i][j];
//printf("%f\t",endImage[i-IMAGEWIDTH/4][j]);
}
//printf("\n");
}
UcharImage(*endImage,*(endcharImage[8*a+b]),IMAGEWIDTH/2,IMAGEHEIGHT/2);//强制转换为float型//对所有的行进行harr变化
/*
switch (imageIndex[a][b])
{
case MODEPHOTO00:
UcharImage(*endImage,*endcharImage00,IMAGEWIDTH/2,IMAGEHEIGHT/2);//强制转换为float型//对所有的行进行harr变化
break;
case MODEPHOTO01:
UcharImage(*endImage,*endcharImage01,IMAGEWIDTH/2,IMAGEHEIGHT/2);//强制转换为float型//对所有的行进行harr变化
break;
case MODEPHOTO02:
UcharImage(*endImage,*endcharImage02,IMAGEWIDTH/2,IMAGEHEIGHT/2);//强制转换为float型//对所有的行进行harr变化
break;
case MODEPHOTO03:
UcharImage(*endImage,*endcharImage03,IMAGEWIDTH/2,IMAGEHEIGHT