遞迴函式後取出最多像素點 |
缺席
|
913028
一般會員 發表:30 回覆:41 積分:19 註冊:2008-06-24 發送簡訊給我 |
各位大大你們好:
以下是我用此討論區的程式碼修改而成,每條線段遞迴完後會記錄一個編號,我要從這個編號中找其像素最多的那條線段, 請問有何方法可以使用的,麻煩大大們給點意見。 感謝 [code cpp] int __fastcall TForm1::CCL(Graphics::TBitmap*TheBitmap, int i, int j) //連通 { int count=0; count ; if (TheBitmap->Canvas->Pixels[i][j]==clWhite) { TheBitmap->Canvas->Pixels[i][j]=clYellow; } //在Memo1秀出(X,Y)位置 Memo1->Lines->Add("X:" IntToStr(i) " Y:" IntToStr(j)); Application->ProcessMessages(); Form1->DoubleBuffered=true; // 雙緩衝區(不讓畫面閃動) if (TheBitmap->Canvas->Pixels[i 1][j]==clWhite) //向右走 { count =CCL(TheBitmap, i 1, j); } if (TheBitmap->Canvas->Pixels[i][j 1]==clWhite) //向下走 { count =CCL(TheBitmap, i, j 1); } if (TheBitmap->Canvas->Pixels[i-1][j]==clWhite) //向左走 { count =CCL(TheBitmap, i-1, j); } if (TheBitmap->Canvas->Pixels[i][j-1]==clWhite) //向上走 { count =CCL(TheBitmap, i, j-1); } if (TheBitmap->Canvas->Pixels[i 1][j-1]==clWhite) //右上 { count =CCL(TheBitmap, i 1, j-1); } if (TheBitmap->Canvas->Pixels[i-1][j-1]==clWhite) //左上 { count =CCL(TheBitmap, i-1, j-1); } if (TheBitmap->Canvas->Pixels[i 1][j 1]==clWhite) //右下 { count =CCL(TheBitmap, i 1, j 1); } if (TheBitmap->Canvas->Pixels[i-1][j 1]==clWhite) //左下 { count =CCL(TheBitmap, i-1, j 1); } return (count); } //---------------------------------------------------------------------------- void __fastcall TForm1::Button14Click(TObject *Sender) { int index; TheBitmap=Image1->Picture->Bitmap; Byte **ptr2; ptr2 = new Byte*[Image1->Picture->Height]; for (int k=0; k ptr2[k] = (Byte*) Image1->Picture->Bitmap->ScanLine[k]; int i,j; int ObjCount = 0;//計算白點像素個數 Memo1->Clear(); for(i=M1;i index = i*3; for(j=M3;j if (ptr2[j][index]==255) { CCL(TheBitmap,i,j); //宣告的函式在上方 CCL ObjCount ; //遞迴完就累積加一 } } } ShowMessage("白線物件個數為" IntToStr(ObjCount) "個");//計算白點像素個數 [/code] 處理如圖
------
新手報到 |
913028
一般會員 發表:30 回覆:41 積分:19 註冊:2008-06-24 發送簡訊給我 |
終於用好了!!
感謝此篇文章的教導=> http://delphi.ktop.com.tw/board.php?cid=168&fid=912&tid=57709
------
新手報到 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |