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

有關角落檢測

尚未結案
yeh95
一般會員


發表:3
回覆:1
積分:0
註冊:2004-07-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-09-13 11:49:48 IP:220.139.xxx.xxx 未訂閱
我第一次些程式.角落檢測卻RUN不出.概念是.先用SOBEL產生的一各邊緣圖.探測邊緣(像素值=255).根據值=255的座標X,Y.產生一各探測視窗大小(2N+1)^2.中心點X,Y.再以這些座標去搜尋二值化的圖.找出物體與背景的比率差來判斷角落.寫的程式碼如下.請大大幫我看看哪裡出錯
 void __fastcall TFormMain::corner()
{
    Graphics::TBitmap *bmp= new Graphics::TBitmap();
    Graphics::TBitmap *bmp2= new Graphics::TBitmap();
    Graphics::TBitmap *bmp3= new Graphics::TBitmap();
    Byte *ptr,*ptr2,*ptr3;
    int gray;
    int i,j,sum=0,x,y;
    int threshold;
    int n=StrToInt(Edit2->Text);
    float p,q;
    ofstream outfile1("A.txt");
    ofstream outfile2("B.txt");
    ofstream outfile3("c.txt");        threshold = ScrollBar1->Position;
    Edit1->Text = ScrollBar1->Position;
    bmp->Assign(Image3->Picture->Bitmap);
    bmp2->Assign(Image5->Picture->Bitmap);
    bmp3->Assign(Image2->Picture->Bitmap);
    for(j=0;jHeight;j++)
    {
      ptr = (Byte *)bmp->ScanLine[j];
      for(i=0; iWidth; i++)
        {
          if(ptr[i]==255)
          {
           outfile1<<'('<ScanLine[y];
            for(x=i-n;x<=i+n;x++)
            {
             if(ptr2[x]==0)
             {
              sum++;
             }
            }
           }
          p=(float)sum/(n+n+1)*(n+n+1);
          q=1-p;              for(j=0;jHeight;j++)
         {
          ptr3=(Byte *)bmp3->ScanLine[j];
          for(i=0; iWidth; i++)
          {
            if(abs(p-q)>threshold)
           {
           ptr3[i*3]=ptr3[i*3+1]=ptr3[i*3+2]=255;
           outfile2<<'('<Picture->Assign(bmp3);
    }
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-09-13 21:52:42 IP:211.76.xxx.xxx 未訂閱
yeh95 您好:    大概看懂您程式要做的事,有些建議您且參考。 1.您在判斷區塊內的值時,其實如果角落就落在靠近影像邊界的地方,這時有可能搜尋區塊會超出影像的範圍。 2.您有好幾個Bitmap,但似乎它們的PixelFormat好像不全然相同,在ScanLine的使用上有可能發生錯放資料,造成顯示結果錯誤。    另外,我覺得有疑問的部分,直接標示在引言中。    
引言: 我第一次些程式.角落檢測卻RUN不出.概念是.先用SOBEL產生的一各邊緣圖.探測邊緣(像素值=255).根據值=255的座標X,Y.產生一各探測視窗大小(2N 1)^2.中心點X,Y.再以這些座標去搜尋二值化的圖.找出物體與背景的比率差來判斷角落.寫的程式碼如下.請大大幫我看看哪裡出錯
 void __fastcall TFormMain::corner()
{
    .....
    int threshold;
    int n=StrToInt(Edit2->Text);
    float p,q;
    .....        threshold = ScrollBar1->Position;  // threshold的值必是整數,最小為0
    Edit1->Text = ScrollBar1->Position;
    .....
    for(j=0;jHeight;j  )
    {
      ptr = (Byte *)bmp->ScanLine[j];
      for(i=0; iWidth; i  )
        {
          if(ptr[i]==255)
          {
           outfile1<<'('<ScanLine[y];
            for(x=i-n;x<=i n;x  )
            {
             if(ptr2[x]==0)
             {
              sum  ;
             }
            }
           }
          p=(float)sum/(n n 1)*(n n 1); // p,q的值均在0與1之間。
          q=1-p;              for(j=0;jHeight;j  )
         {
          ptr3=(Byte *)bmp3->ScanLine[j];
          for(i=0; iWidth; i  )
          {
            if(abs(p-q)>threshold)  // 除非threshold為零,否則條件恆不成立!因為 abs(p-q) < = 1
           {
           ptr3[i*3]=ptr3[i*3 1]=ptr3[i*3 2]=255;
           outfile2<<'('<Picture->Assign(bmp3);
    }
RichTop 敬上 =====***** 把數學當工具,可以解決問題;將數學變能力,能夠發現並解決問題! =====#####
系統時間:2024-05-21 5:28:57
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!