有關8連通connected component的問題 |
答題得分者是:taishyang
|
lincher
一般會員 發表:10 回覆:2 積分:2 註冊:2005-09-14 發送簡訊給我 |
請問一下~
我有參考前輩們的做法使用8連通的connected component
如下:
void __fastcall TForm5::ComConnect(Graphics::TBitmap* BMP,int x,int y) { BMP->Canvas->Pixels[x][y]=clBlack; Image4->Canvas->Pixels[x][y]=clYellow; if(BMP->Canvas->Pixels[x+1][y]==clWhite) ComConnect(BMP,x+1,y); if(BMP->Canvas->Pixels[x+1][y+1]==clWhite) ComConnect(BMP,x+1,y+1); if(BMP->Canvas->Pixels[x][y+1]==clWhite) ComConnect(BMP,x,y+1); if(BMP->Canvas->Pixels[x-1][y+1]==clWhite) ComConnect(BMP,x-1,y+1); if(BMP->Canvas->Pixels[x-1][y]==clWhite) ComConnect(BMP,x-1,y); if(BMP->Canvas->Pixels[x-1][y-1]==clWhite) ComConnect(BMP,x-1,y-1); if(BMP->Canvas->Pixels[x][y-1]==clWhite) ComConnect(BMP,x,y-1); if(BMP->Canvas->Pixels[x+1][y-1]==clWhite) ComConnect(BMP,x,y-1); } //--------------------------------------------------------------------------- void __fastcall TForm5::detection1Click(TObject *Sender) { int ObjCount=0; Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; Bmp->Assign(Image4->Picture->Bitmap ); for(int y = 0; y < Bmp->Height; y++) { ptr = (Byte *) Bmp->ScanLine[y]; for(int x = 0; x < Bmp->Width; x++) { if(ptr[x*3] == 255) { ComConnect(Bmp, x, y); ObjCount++; //遞迴完就累積加一 break; } } } ShowMessage("物件個數為"+IntToStr(ObjCount)+"個"); delete Bmp; }如果跑下面這張圖的話,那10個元件是可以搜尋到的 (因為我是做膚色區域給他二值化,所以做完二值化後,那10個元件都會是白色) 可是如果跑下面這張圖的話,就會跑出"stack overflow"的錯誤顯示 請問是為麼呢?該如何解決 謝謝 發表人 - lincher 於 2005/11/01 19:33:21 |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
lincher
一般會員 發表:10 回覆:2 積分:2 註冊:2005-09-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |