線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:850
推到 Plurk!
推到 Facebook!

有關於二值化再加上低通率波的問題

尚未結案
residue
中階會員


發表:90
回覆:153
積分:53
註冊:2003-07-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-16 14:54:06 IP:203.64.xxx.xxx 未訂閱
版大你好   小弟遇個很怪的問題,小弟本來是用低通率波加上二值化處理空間中的三個圓(圓是會轉動的),在進而擷取三圓之中心,但遇到一個很奇怪的問題,若影像處理的好的話,三個圓會抓到三個點但小弟怎麼抓都有多出一點,而且那一點的座標還是固定的,並不會變動,但若單用二值化不用低通率波就沒此問題囉!!所以小弟也不知錯在哪邊,還請大大指導 以下就是小弟的程式以及擷取的圖片 < class="code"> void __fastcall TCap::bricy()//二直化 { Graphics::TBitmap *bmp = new Graphics::TBitmap(); Byte *ptr; int gray; int i,j; int threshold; int thrd1; threshold = Form1->ScrollBar1->Position; thrd1 = Form1->ScrollBar4->Position; Form1->Edit1->Text = Form1->ScrollBar1->Position; Form1->Edit16->Text = Form1->ScrollBar4->Position; bmp->Assign(Form1->Image1->Picture->Bitmap); bmp->PixelFormat=pf24bit; //------------------------- 二值化微調 ------------------------ for(j=0; jHeight; j++) { ptr = (Byte *)bmp->ScanLine[j]; for(i=0; iWidth*3; i++) { if (ptr[i] >thrd1) ptr[i]=255; else ptr[i]=0; gray = (ptr[i]*28 + ptr[i+1]*151 +ptr[i+2]*77)/256; ptr[i] = ptr[i+1] = ptr[i+2] = (Byte)gray; } } //------------- ------------ ------------------------ for(j=0; jHeight; j++) { ptr = (Byte *)bmp->ScanLine[j]; for(i=0; iWidth*3; i+=3) { gray = (ptr[i]*28 + ptr[i+1]*151 +ptr[i+2]*77)/256; if(gray > threshold) gray = 255; else gray = 0; ptr[i] = ptr[i+1] = ptr[i+2] = (Byte)gray; } } //======================================================================= for(int i=0;iHeight;i++ ) //低通率波 { ptr=(Byte*)bmp->ScanLine[i]; for (int j=0;jWidth*3; j++ ) { p1[j][i]=ptr[j*3]; } } for (int i=0;iHeight;i++ ) { ptr=(Byte*)bmp->ScanLine[i]; for (int j=0;jWidth*3; j++ ) { ptr[j*3]=LowpassFilter1Click(j,i); ptr[j*3+1]=LowpassFilter1Click(j,i); ptr[j*3+2]=LowpassFilter1Click(j,i); } } //======================================================= Form1->Image2->Picture->Assign(bmp); delete bmp; } 以下是擷取中心程式
 
void __fastcall TCap:: vAddToList(int LsNo,int x,int y,int w)
{
  int i;
  AnsiString ss;
  for (i=0;iAdd(ss);
  }
}     int __fastcall TCap:: iInList(int LsNo,int x,int y,int w)
{
  int i,j;
  AnsiString ss;
  int xx,yy;      for (i=Ls[LsNo]->Count-1;i>0;i--)
  {
    ss = Ls[LsNo]->Strings[i];
    sscanf(ss.c_str(),"%d%d",&xx,&yy);
    if (yy == y-1)
    {
      for (j=0;jCount)
    {
      if (iInList(i,x,y,w)) break;
    } else
    {
      vAddToList(i,x,y,w);
      break;
    }
  }
}
 int __fastcall TCap:: iBlackDot(int x,int y,int w,Byte *ptr)
{
  int i;
  for (i=1; iCount;i++)
  {
    ss = Ls[LsNo]->Strings[i];
    sscanf(ss.c_str(),"%d%d",&xx,&yy);        sumX += xx;
    sumY += yy;
  }      sumX /= Ls[LsNo]->Count;
  sumY /= Ls[LsNo]->Count;
   Form1->Image4->Canvas->Pen->Color = clBlue;       Form1->Image4->Canvas->TextOutA(sumX,sumY,AnsiString(sumX)+","+sumY);
   Form1->Memo1->SelText ="   "+AnsiString(sumX)+","+sumY  ;
   Form1->Image4->Canvas->Pen->Color=clRed;
   Form1->Image4->Canvas->Ellipse(sumX+2,sumY+2,sumX-2,sumY-2);
delete bmp;           }    //--------------------------------------------------------------------    void __fastcall TCap::BCK1()//掃秒圖
{
 Graphics::TBitmap *bmp = new Graphics::TBitmap();
 bmp->Assign(Form1->Image2->Picture->Bitmap);
 bmp->PixelFormat=pf24bit;      Byte *ptr;
  starttime=clock();
  for (int y = 0; y Height; y++)
  {
    ptr = (Byte *)bmp->ScanLine[y];        for (int x = 0; x < bmp->Width; x++)
    {
      //不是白色
      if (ptr[3*x]!=255||ptr[3*x+1]!=255||ptr[3*x+2]!=255)
      {
        x += iBlackDot(x,y,bmp->Width,ptr);
      }        }
  }
delete bmp;
  for (int i=0;i<10;i++)
  {
    if (Ls[i]->Count)
    {
      vCalDot(i);
    }
  }        endtime=clock();
totaltime=(endtime-starttime)/CLK_TCK;
Form1->Edit18->Text=totaltime;    }    void __fastcall TCap::BCK3()
{       for (int i=0;i<10;i++)
  {
    Ls[i] = new TStringList();
  }    }    
上圖是二值化加上低通率波 上圖紅點是圓的中心
residue
中階會員


發表:90
回覆:153
積分:53
註冊:2003-07-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-17 17:11:08 IP:203.64.xxx.xxx 未訂閱
問題已經決解囉!! 原來在image肉眼看不到並不代表,沒有色彩!!
系統時間:2024-05-11 4:18:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!