再牛的人也永远看不懂这段程序!
void computeF(IplImage* img,int* feature){
uchar* imgdate;
int height=train->height;
int width=train->width;
int indexadd=-1,index=0,begin=0;
for (int h=0;h<height;h++)
{
imgdate=(uchar*)(img->imageData+h*train->widthStep);
begin=0;
for (int w=0;w<width;w++)
{
if (w!=width-1&&imgdate[3*w]==0&&imgdate[3*w+1]==0&&imgdate[3*w+2]==0&&imgdate[3*(w+1)]==255&&imgdate[3*(w+1)+1]==255&&imgdate[3*(w+1)+2]==255) //黑白跳跃
{
indexadd++;
if (w<width/3&&h<height/2)
{
if (indexadd>1) //接触2次黑白跳跃
{
w=width/3-1;
begin=width/3;
indexadd=-1;
continue;
}
index=0+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (w<2*width/3&&h<height/2)
{
if (indexadd>1)
{
w=2*width/3-1;
begin=2*width/3;
indexadd=-1;
continue;
}
index=2+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (w<width&&h<height/2)
{
if (indexadd>1)
{
indexadd=-1;
break;
}
index=4+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (w<width/3&&h<height)
{
if (indexadd>1)
{
w=width/3-1;
begin=width/3;
indexadd=-1;
continue;
}
index=6+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (w<2*width/3&&h<height)
{
if (indexadd>1)
{
w=2*width/3-1;
begin=2*width/3;
indexadd=-1;
continue;
}
index=8+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (w<width&&h<height)
{
if (indexadd>1)
{
indexadd=-1;
break;
}
index=10+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
if (w==width/3-1)
{
if (h<height/2)
{
if (indexadd==0)
{
indexadd=1;
}
if (indexadd==-1)
{
indexadd=0;
}
index=0+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (h<height)
{
if (indexadd==0)
{
indexadd=1;
}
if (indexadd==-1)
{
indexadd=0;
}
index=6+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
}
if (w==2*width/3-1)
{
if (h<height/2)
{
if (indexadd==0)
{
indexadd=1;
}
if (indexadd==-1)
{
indexadd=0;
}
index=2+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
else if (h<height)
{
if (indexadd==0)
{
indexadd=1;
}
if (indexadd==-1)
{
indexadd=0;
}
index=8+indexadd;
feature[index]+=w-begin+1;
begin=w+1;
}
}
if (w==width-1)
{
if (h<height/2)
{
if (indexadd==0)
{
indexadd=1;
}
if (indexadd==-1)
{
indexadd=0;
}
index=4+indexadd;
feature[index]+=w-begin+1;
}
else if (h<height)
{
if (indexadd==0)
{
indexadd=1;
}
if (indexadd==-1)
{
indexadd=0;
}
index=10+indexadd;
feature[index]+=w-begin+1;
}
}
}
}
}
}