⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eightarrayfeature.pas

📁 模板匹配之手写数字识别系统,基于DELPHI 7.0
💻 PAS
字号:
unit EightArrayFeature;

interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, CharFeatureValue;

type
    //8*8矩阵分析类
    TEightArrayFeature = class
    private
        pic: Tbitmap;
        function Statistic(const rect: Trect):integer;    //  统计某一个区域的点个数
    public
        procedure SetPicFile(const Filename: string);    //  读入分析用的图片
        function GetDoubleEightArray: TDoubleEightArray; //  获得8X8矩阵特征
    end;
implementation

{ EightArrayFeature }

//  获得8x8矩阵特征
function TEightArrayFeature.GetDoubleEightArray:TDoubleEightArray;
var
    w, h:   integer;
    i, j:   integer;
    max:    integer;
    s:  array [1..8, 1..8] of integer;
    Rect:   Trect;
begin
    if pic <> nil then
    begin
        w := pic.Width mod 8;
        pic.Width := pic.Width + 8 - w;
        w := pic.Width div 8;
        h := pic.Height mod 8;
        pic.Height := pic.Height + 8 - h;
        h := pic.Height div 8;
        max := 0;
        for i := 1 to 8 do
            for j := 1 to 8 do
            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 i := 1 to 8 do
            for j := 1 to 8 do
            begin
                if s[i, j] / max > 0.2 then
                    Result[i, j] := 1
                else
                    Result[i, j] := 0;
            end;
end;


end;

//  读入分析用的图片
procedure TEightArrayFeature.setPicFile(const filename: string);
begin
    if FileExists(filename) then
    begin
        if pic = Nil then
            pic := Tbitmap.Create;
        pic.LoadFromFile(filename);
    end;

end;  
//  统计某一个区域的点个数
function TEightArrayFeature.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 pic.Canvas.Pixels[x, y] <> 16777215 then
                inc(Result);

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -