將圖片二值化後出現錯誤 |
尚未結案
|
小丫123
初階會員 發表:85 回覆:62 積分:29 註冊:2004-08-31 發送簡訊給我 |
var idx:integer; orginalwidth:integer; orginalheight:integer; function TForm1.Statistic(const rect: Trect): integer;//对区域内黑象素的统计 var x,y:integer; begin Result:=0; for x:=rect.Left to rect.Right do for y:=rect.Top to rect.Bottom do if img.Canvas.Pixels[x,y]<>16777215 then inc(result); end; procedure TForm1.Button1Click(Sender: TObject); var i,j:integer; w,h:integer; s,result:array[1..20,1..20] of integer; max:integer; rect:Trect; t:string; begin //读取edit1.text里的字符 for idx:=1 to length(edit1.text) do begin memo1.Clear ; Image1.Canvas.Font.Color := clRed; Image1.Canvas.Font.Size := 42; if Edit1.Text <> '' then begin image1.Canvas.TextOut(0, 0, edit1.Text[idx]) ; img.picture.Bitmap.Assign(image1.picture.Bitmap); end; //将图片0~1化 if img <> nil then begin img.Width:= orginalwidth; img.height:=orginalheight; w:=img.Width mod 30; img.Width:=img.Width 30-w; w:=img.Width div 30; h:=img.Height mod 30; img.Height :=img.Height 30 -h; h:= img.Height div 30; max:=0; for i:=1 to 20 do for j:=1 to 20do begin rect.Left :=w*(i-1); rect.Top :=h*(j-1); rect.Right :=rect.Left w-1; rect.Bottom :=rect.Top h-1; s[i,j]:=statistic(rect); if s[i,j]>max then max:=s[i,j]; end; for j:=1 to 20 do begin t:=''; for i:=1 to 20 do begin if s[i,j]/max >0.2 then Result[i,j]:=1 else Result[i,j]:=0; t:= t inttostr(Result[i,j]) ' ' ; end; memo1.Lines.Add(t) ; end; end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin idx := 1; orginalwidth:=180; orginalheight:=240; end; end.这个程序的结果本来应该是30×30的0 1矩阵,看结果时候我的img.width height变得很小,不知道错在哪里啊? 恳请各位前辈指点 |
deity
尊榮會員 發表:90 回覆:876 積分:678 註冊:2003-05-09 發送簡訊給我 |
引言:var idx:integer; orginalwidth:integer; orginalheight:integer; function TForm1.Statistic(const rect: Trect): integer;//对区域内黑象素的统计 var x,y:integer; begin Result:=0; for x:=rect.Left to rect.Right do for y:=rect.Top to rect.Bottom do if img.Canvas.Pixels[x,y]<>16777215 then inc(result); end; procedure TForm1.Timer1Timer(Sender: TObject);这个程序的结果本来应该是30×30的0 1矩阵,看结果时候我的img.width height变得很小,不知道错在哪里啊? 恳请各位前辈指点 至于矩阵,应该是20×20吧,小弟测试img的大小也没有变得很小,应该是对的吧,理解错误,请见凉,> >>< face="Verdana, Arial, Helvetica"> ——行径窄处,留一步与人行—— |
小丫123
初階會員 發表:85 回覆:62 積分:29 註冊:2004-08-31 發送簡訊給我 |
多谢deity。
在这个程序中,本来如果是对1进行二值化出来的结果应该是:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
可是这个程序不知道哪里出错了,出来的结果是错误的。程序不知道哪里还有错误呢? 發表人 - 小丫123 於 2004/11/04 15:18:40
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |