二值化图形中物件的个数 |
尚未結案
|
小丫123
初階會員 發表:85 回覆:62 積分:29 註冊:2004-08-31 發送簡訊給我 |
我想在一个白色背景下的图像中,将黑色的不同连通体的个数计算出来,再将每个连通体的象素值算出来。
我参考了http://delphi.ktop.com.tw/topic.php?TOPIC_ID=50190
可是将其改成delphi语言时,出现了错误,恳请各位前辈帮忙指错,不胜感激
procedure TForm1.Button1Click(Sender: TObject); var c,cx,x,y:integer; bmp1: Tbitmap; p:PByteArray; begin bmp1 := Tbitmap.Create; bmp1.Assign(image4.Picture.Bitmap); for y:=0 to bmp1.Height do begin p:=bmp1.ScanLine[y]; for x:=0 to bmp1.Width do begin if (p[x*3]=255) then begin cx:=connect(bmp1,x,y); memo1.Lines.Add(inttostr(cx));// 每个物件的象素点数和 count:=0; c:=c 1; end; end; memo1.Lines.Add('一共有以下几个物件'); memo1.Lines.Add(inttostr(c)); bmp1.Free ; end; function TForm1.Connect(BMP: TBitmap; x, y: integer): integer;Statement expected but 'function' found var P,Q,R:PByteArray; begin count:=count 1; //象素点数 P:=bmp.ScanLine[Y]; Q:=bmp.ScanLine [Y-1]; R:=bmp.ScanLine [Y 1] P[3*x]=255 if (P[3*(x 1)]=0) then //判断(x 1,y) connect(bmp,x 1,y);'Byte'and 'procedure, untyped pointer or untyped parameter' if(Q[3*(x 1)]=0) then //判断(x 1,y-1) connect(bmp,x 1,y-1); if(R[3*(x 1)]=0) then //判断(x 1,y 1) connect(bmp,x 1,y 1); if(Q[3*x]=0) then //判断(x,y-1) connect(bmp,x,y-1); if(R[3*x]=0) then //判断(x,y 1) connect(bmp,x,y 1); if (P[3*(x-1)]=0)then //判断(x-1,y) connect(bmp,x-1,y); if(Q[3*(x-1)]=0) then //判断(x-1,y-1) connect(bmp,x-1,y-1) if(R[3*(x-1)]=0) then // 判断(x-1,y 1) connect(bmp,x-1,y 1); Result:=count; end;这个程式有报错说:“Statement expected but 'function' found” "'Byte'and 'procedure, untyped pointer or untyped parameter' 研二的女生 |
Chance36
版主 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
引言:_______________________________________ 深藍的魚,祝您好運..........連連procedure TForm1.Button1Click(Sender: TObject); var c,cx,x,y:integer; bmp1: Tbitmap; p:PByteArray; begin bmp1 := Tbitmap.Create; bmp1.Assign(image4.Picture.Bitmap); for y:=0 to bmp1.Height do begin p:=bmp1.ScanLine[y]; for x:=0 to bmp1.Width do begin if (p[x*3]=255) then begin cx:=connect(bmp1,x,y); memo1.Lines.Add(inttostr(cx));// 每个物件的象素点数和 count:=0; c:=c 1; end; end; memo1.Lines.Add('一共有以下几个物件'); memo1.Lines.Add(inttostr(c)); bmp1.Free ; end; //少了一個end ; 你加上之後,後面的錯誤就應該不會出現了 end; |
小丫123
初階會員 發表:85 回覆:62 積分:29 註冊:2004-08-31 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
看對不對:
procedure TForm1.Button1Click(Sender: TObject); var c,cx,x,y: integer; bmp1: Tbitmap; p: PByteArray; begin memo1.Lines.Clear; bmp1 := Tbitmap.Create; try bmp1.Assign(image4.Picture.Bitmap); c:=0 ; for y:=0 to bmp1.Height-1 do begin p := bmp1.ScanLine[y]; for x := 0 to bmp1.Width-1 do begin if (p[x*3]=255) then begin cx := connect(bmp1,x,y); memo1.Lines.Add(inttostr(cx));// 藩跺昜璃腔砓匼萸杅睿 count := 0; c := c 1; end; end; memo1.Lines.Add('珨僕衄眕狟撓跺昜璃'); memo1.Lines.Add(inttostr(c)); end; finally bmp1.Free; end; showmessage('done!'); end; function TForm1.Connect(BMP: TBitmap; x, y: integer): integer; begin count := count 1; BMP.Canvas.Pixels[x, y] := clBlack; // 判斷 (x 1,y) if (BMP.Canvas.Pixels[x 1,y] = clWhite) then Connect(BMP, x 1, y); // 判斷(x 1, y - 1) if (BMP.Canvas.Pixels[x 1,y - 1] = clWhite) then Connect(BMP, x 1, y - 1); // 判斷 (x 1,y 1) if (BMP.Canvas.Pixels[x,y - 1] = clWhite) then Connect(BMP, x , y - 1); // 判斷 (x,y-1) if (BMP.Canvas.Pixels[x-1,y - 1] = clWhite) then Connect(BMP, x-1, y - 1); // 判斷 (x,y-1) if (BMP.Canvas.Pixels[x-1,y] = clWhite) then Connect(BMP, x-1, y); // 判斷 (x-1,y) if (BMP.Canvas.Pixels[x - 1, y 1] = clWhite) then Connect(BMP, x - 1, y 1); // 判斷 (x-1,y-1) if (BMP.Canvas.Pixels[x,y 1] = clWhite) then Connect(BMP, x, y 1); // 判斷 (x 1,y) if (BMP.Canvas.Pixels[x 1,y 1] = clWhite) then Connect(BMP, x 1, y 1); // 判斷 (x-1,y 1) if (BMP.Canvas.Pixels[x 1,y] = clWhite) then Connect(BMP, x 1, y); Result := count; end;-- 分擔可以輕省, 分享帶來喜樂! 發表人 - hagar 於 2005/04/01 16:55:35 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |