void CMainFrame::OnCaptureRtpMotiondetect() 
{
// TODO: Add your command handler code here
AfxMessageBox("优");
}void CMainFrame::OnDengji() 
{
// TODO: Add your command handler code here
// myView->bmpdatabuff2 = new BYTE [WIDTH * HEIGHT* 3];
// tempfloat=10*rand();
int Horizon[HEIGHT] , Vert[WIDTH];
for(int i=0; i<HEIGHT;i++) Horizon[i]=0;
for(int j=0; j<WIDTH;j++) Vert[j]=0;
// BYTE *Value = myView->bmpdatabuff2;
   BYTE *Value = new BYTE [WIDTH * HEIGHT* 3];
for(i = 0; i< HEIGHT; i++)
for(j = 0; j< WIDTH ; j++)
{
if(*(Value+i*3*WIDTH+3*j)&0xff == 255 )  
{
Horizon[i]++;
    Vert[j]++;
}
}


int temp=0,temp2=0;  
int x_start=-1,x_end=-1;
int y_start=-1,y_end=-1;
                                                                                                                                        
for(j = 8; j< WIDTH-8; j++)
{
 temp =temp2 =0;  for(int x=0; x<8;x++)
{
temp += Vert[j-x-1];
temp2 += Vert[j+x+1];
}  if(abs((temp2/8 - temp/8)/2) > 20) 
 {
x_start = j;
AfxMessageBox("! 优 !!");
break;  
 }
}
for(j = WIDTH-8; j>=8 ; j--)
{
 temp =temp2 =0;  for(int x=0; x<8;x++)
{
temp += Vert[j-x-1];
temp2 += Vert[j+x+1];
}  if(abs((temp2/8 - temp/8)/2) >20) 
 {
x_end = j;
AfxMessageBox("!!  中等  !!");
break;  
 }

} for(i = HEIGHT-10; i>= 8; i--)
{
temp = 0;
for(int x=0; x<8;x++)
temp += Horizon[i-x-1];
 if(abs(Horizon[i] - temp /8) <20 && Horizon[i] !=0 )
 {
 y_start = HEIGHT-i;
  AfxMessageBox("!! 低等 !!");
 break;
 }
}

解决方案 »

  1.   

    if(*(Value+i*3*WIDTH+3*j)&0xff == 255 )  

    Horizon[i]++; 
        Vert[j]++; temp =temp2 =0; for(int x=0; x <8;x++) 

    temp += Vert[j-x-1]; 
    temp2 += Vert[j+x+1]; 
    } if(abs((temp2/8 - temp/8)/2) > 20) 

    x_start = j; 
    AfxMessageBox("! 优 !!"); 尤其是这几行 小弟 不明白 急求高手解答下
      

  2.   

    条件不是有了吗?
    if(abs((temp2/8 - temp/8)/2) > 20) //这个就是

    x_start = j; 
    AfxMessageBox("! 优 !!"); 
    break; 
    }//abs取正值,取绝对值函数
    //当temp2除以8减去temp除以8的差的一半的绝对值大于20,就判定是“优”
      

  3.   

    感谢这位大侠了!!小弟对C++不感冒
    还有就是判断优时是这个for(j = 8; j < WIDTH-8; j++) 

    temp =temp2 =0; for(int x=0; x <8;x++) 
    判断中等时是for(j = WIDTH-8; j>=8 ; j--) 

    temp =temp2 =0; for(int x=0; x <8;x++) 
    { 为什么j=8   
    哪位大虾能帮我详细解释下那一大段代码
      

  4.   

    if 就是条件呀,你写这个if语句的时候,不会不知道条件就能写吧
      

  5.   

    感谢6楼的大侠  if这个我懂  但是为什么 for(int x=0; x <8;x++)要循环8次