반응형

LRESULT CALLBACK capCallbackOnFrame(HWND hWnd, LPVIDEOHDR lpVHdr)
{
 BYTE pixel;
 int  i,j,index,counter=0;

 if(pImageBuffer==NULL)
  pImageBuffer= (LPBYTE)new BYTE[BmInfo.bmiHeader.biHeight*BmInfo.bmiHeader.biWidth];

 for (i = 0; i <BmInfo.bmiHeader.biWidth*BmInfo.bmiHeader.biHeight; i++)
 {
   pixel = (*(lpVHdr->lpData + (i*3)    ) +
         *(lpVHdr->lpData + (i*3) + 1) +
      *(lpVHdr->lpData + (i*3) + 2) ) / 3;

   if(pixel > 200) *(pImageBuffer+i) = 255;
   else *(pImageBuffer+i) = 0;
 }

 int xCenter=0, yCenter=0;
 for(i=0; i<BmInfo.bmiHeader.biHeight; i++)
 {
  index = i*BmInfo.bmiHeader.biWidth;
  for(j=0; j<BmInfo.bmiHeader.biWidth; j++)
  {
   if( *(pImageBuffer+index+j) == 255)
   {
    xCenter += i;
    yCenter += j;
    counter++;
   }
 }}
 xCenter =(int)((float)xCenter/(float)counter);
 yCenter =(int)((float)yCenter/(float)counter);
int kasd=0;
kasd=(float)xCenter+(int)30;
int kase=0;
kase=(float)xCenter-(int)30;
 for(i=xCenter-15; i<=xCenter+15; i++)
 {
  if(i<0 || i>=BmInfo.bmiHeader.biHeight) continue;
  index = i*BmInfo.bmiHeader.biWidth;
  *(lpVHdr->lpData + 3*(index+yCenter)) =0;
  *(lpVHdr->lpData + 3*(index+yCenter)+1)   =0;
  *(lpVHdr->lpData + 3*(index+yCenter)+2)   =255;
 }

 index = xCenter*BmInfo.bmiHeader.biWidth;
 for(j=yCenter-15; j<=yCenter+15; j++)
 {
  if(j<0 || j>=BmInfo.bmiHeader.biWidth) continue;
  *(lpVHdr->lpData + 3*(index+j)) =0;
  *(lpVHdr->lpData + 3*(index+j)+1)  =0;
  *(lpVHdr->lpData + 3*(index+j)+2)  =255;
 }


 for(j=yCenter-30; j<=yCenter+30; j++)
 {
  int kase=0;
  kase =xCenter+30;
 index = kase*BmInfo.bmiHeader.biWidth;
 if(j<0 || j>=BmInfo.bmiHeader.biWidth) continue;
 *(lpVHdr->lpData + 3*(index+j)) =0;
 *(lpVHdr->lpData + 3*(index+j)+1)  =255;
 *(lpVHdr->lpData + 3*(index+j)+2)  =0;
 }


 for(j=yCenter-30; j<=yCenter+30; j++)
 {
  int kase=0;
  kase =xCenter-30;
  index = kase*BmInfo.bmiHeader.biWidth;
  if(j<0 || j>=BmInfo.bmiHeader.biWidth) continue;
  *(lpVHdr->lpData + 3*(index+j)) =0;
  *(lpVHdr->lpData + 3*(index+j)+1)  =255;
  *(lpVHdr->lpData + 3*(index+j)+2)  =0;
 }

 for(j=xCenter-30; j<=xCenter+30; j++)
 {
  int kase=0;
  kase=yCenter-30;
 
  index = j*BmInfo.bmiHeader.biWidth;
  if(j<0 || j>=BmInfo.bmiHeader.biWidth) continue;
  *(lpVHdr->lpData + 3*(index+kase)) =0;
  *(lpVHdr->lpData + 3*(index+kase)+1)  =255;
  *(lpVHdr->lpData + 3*(index+kase)+2)  =0;
 }


 for(j=xCenter-30; j<=xCenter+30; j++)
 {
  int kase=0;
  kase=yCenter+30;

  index = j*BmInfo.bmiHeader.biWidth;
  if(j<0 || j>=BmInfo.bmiHeader.biWidth) continue;
  *(lpVHdr->lpData + 3*(index+kase)) =0;
  *(lpVHdr->lpData + 3*(index+kase)+1)  =255;
  *(lpVHdr->lpData + 3*(index+kase)+2)  =0;
 }






 // 차이가 나는 화소의 수를 caption bar에 표시
 CString  strTitle;
 strTitle.Format("Binary Tracker (%d,%d)", xCenter, yCenter);
 AfxGetMainWnd()->SetWindowText(strTitle);

 return (LRESULT)TRUE;
}












///////////////////////x y 가 반대

반응형

+ Recent posts