全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1890
推到 Plurk!
推到 Facebook!

動態邊緣化

 
poaivy
中階會員


發表:40
回覆:78
積分:53
註冊:2004-08-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-28 21:22:12 IP:140.117.xxx.xxx 未訂閱
參考了版上多位大大的發表寫出來的^^ 使用TVideoCapture元件所寫 第一次發表請多多指教
fusung
中階會員


發表:26
回覆:169
積分:99
註冊:2003-11-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-08 15:23:27 IP:211.23.xxx.xxx 未訂閱
做了些修改,各位可以參考看看。    
 
 int __fastcall TForm1::Gx(int i,int j)
{               //sobel-x
 int p[10];

 //考慮邊界
 if (i==0) i=1;
 if (i== Image1->Height) i = Image1->Height - 1;
 if (j==0) j=1;
 if (j== Image1->Width) j = Image1->Width - 1;     p[1]=p1[i-1][j-1];
 p[2]=p1[i][j-1];
 p[3]=p1[i+1][j-1];
 p[4]=p1[i-1][j];
 p[5]=p1[i][j];
 p[6]=p1[i+1][j];
 p[7]=p1[i-1][j+1];
 p[8]=p1[i][j+1];
 p[9]=p1[i+1][j+1];
 int GX=((p[7]+(p[8]*2)+p[9])-(p[1]+(p[2]*2)+p[3]));
 if (GX>255)
  return 255;
 else
  return (abs(GX));
}
//---------------------------------------------------------------------------
int __fastcall TForm1::Gy(int i,int j)
{                //sobel-y
 int p[10];     //考慮邊界
 if (i==0) i=1;
 if (i== Image1->Height) i = Image1->Height - 1;
 if (j==0) j=1;
 if (j== Image1->Width) j = Image1->Width - 1;     p[1]=p1[i-1][j-1];
 p[2]=p1[i][j-1];
 p[3]=p1[i+1][j-1];
 p[4]=p1[i-1][j];
 p[5]=p1[i][j];
 p[6]=p1[i+1][j];
 p[7]=p1[i-1][j+1];
 p[8]=p1[i][j+1];
 p[9]=p1[i+1][j+1];
 int GY=((p[3]+(p[6]*2)+p[9])-(p[1]+(p[4]*2)+p[7]));
 if (GY>255)
  return 255;
 else
  return (abs(GY));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::capBitmapGrabbed(TCapturedBitmap *CapturedImage)
{
switch (RadioGroup1->ItemIndex)
{
case 0:
 Byte *ptr;
 for (int i=0;iHeight;i++ )
 {
  ptr=(Byte*)CapturedImage->ScanLine[i];
  for (int j=0;jWidth; j++ )
  {
// p1[j][i]=ptr[j*3];       p1[i][j]=ptr[j*3];      }
 }
 for (int i=0;iHeight;i++ )
 {
  ptr=(Byte*)CapturedImage->ScanLine[i];
  for (int j=0;jWidth; j++)
   {
   // if ((Gx(j,i)+Gy(j,i))>255)        if ((Gx(i,j)+Gy(i,j))>255)        {
       ptr[j*3]=255;
     ptr[j*3+1]=255;
     ptr[j*3+2]=255;
    }
    else
    {           ptr[j*3]=Gx(i,j)+Gy(i,j);
     ptr[j*3+1]=Gx(i,j)+Gy(i,j);
     ptr[j*3+2]=Gx(i,j)+Gy(i,j);    /*
     ptr[j*3]=Gx(j,i)+Gy(j,i);
     ptr[j*3+1]=Gx(j,i)+Gy(j,i);
     ptr[j*3+2]=Gx(j,i)+Gy(j,i);
*/        }
   }
  }
  Image1->Picture->Assign(CapturedImage);
  break;    
/*
------


The first step toward proving things for yourself is to understand how others have done it before!

系統時間:2024-06-27 0:31:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!