計算compoent的pixel數 |
尚未結案
|
lincher
一般會員 發表:10 回覆:2 積分:2 註冊:2005-09-14 發送簡訊給我 |
請教各位前輩~
如果我有一張圖如下 做完connected-compoent之後可以找出那12個物件
如圖下(找出的物件以黃色顯示) 請問我該如何計算出每一個物件中的pixel值呢?
謝謝...
程式碼如下~~乃參考前輩們的程式碼..
-------------------//副程式//------------------------------------- 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 num=0; int *A= new int[num]; ZeroMemory(A,sizeof(int)*num); //動態宣告陣列 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); num++; } } } ShowMessage("物件個數為"+IntToStr(num)+"個"); delete Bmp; delete [] A; }發表人 - lincher 於 2005/11/01 22:21:16 |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |