用delphi比较两张图片的相似度

本文深入解析了一种图像识别算法的实现过程,通过加载特定的位图文件,提取图像特征点并进行比对,实现了对数字图像的有效识别。该算法首先初始化特征点列表,接着加载图像并提取背景颜色,然后遍历图像像素,将非背景颜色的像素位置记录为特征点,最后通过比较特征点集合来识别图像中的数字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

procedure TFrm_test.initList;
var
idx, i, k, x, y, l: integer;
p, fn:
string;
bmp: TBitmap;
BColor, NowColor: TColor;
begin

p :
= ExtractFilePath(Application.ExeName);
bmp :
= TBitmap.Create;
for i := 0 to 9 do
begin
fn :
= p + '\CodeBmp\ ' + IntToStr(i) + '.bmp ';
if not FileExists(fn) then
Continue;

idx :
= length(PointRecList);
SetLength(PointRecList, idx
+ 1);
PointRecList[idx].Code :
= IntToStr(i);

bmp.LoadFromFile(fn);
BColor :
= bmp.Canvas.Pixels[0, bmp.Height - 1];

for x := 0 to bmp.Width - 1 do
for y := 0 to bmp.Height - 1 do
begin
NowColor :
= bmp.Canvas.Pixels[x, y];
if NowColor <> BColor then
begin
l :
= length(PointRecList[idx].PointList);
SetLength(PointRecList[idx].PointList, l
+ 1);
PointRecList[idx].PointList[l].x :
= x;
PointRecList[idx].PointList[l].y :
= y;
end;
end;

end;

FreeAndNil(bmp);

//
end;

function getCode_Bmp(const bmp: TBitmap; strLen: integer;
PointRecList:
array of TPointRec): string;
var
j, i, l, x, y, x0, xS, beginx: integer;

BColor, NowColor: TColor;
PointList:
array of TPoint;
function getCode: string;
var
maxCount, k, m, j, i: integer;

begin
Result :
= '? ';
if length(PointList) < 3 then
exit;

maxCount :
= 0;
for i := 0 to high(PointRecList) do
begin

if length(PointRecList[i].PointList) < 3 then
Continue;

m :
= 0;

for k := 1 to high(PointList) do
begin

for j := 1 to high(PointRecList[i].PointList) do
if ((PointList[k].x - PointList[0].x) =
(PointRecList[i].PointList[j].x
- PointRecList[i].PointList[0].x)
)
and ((PointList[k].y - PointList[0].y) =
(PointRecList[i].PointList[j].y
- PointRecList[i].PointList[0].y)
)

then
begin
inc(m);
Break;
end;

end;

m :
= m * 100 div (length(PointList) - 1);
if m > maxCount then
begin
Result :
= PointRecList[i].Code;
maxCount :
= m;
end;
end;
end;

begin
Result :
= ' ';
BColor :
= bmp.Canvas.Pixels[0, bmp.Height - 1];
x0 :
= 0;
xS :
= bmp.Width div strLen;
for i := 0 to strLen - 1 do
begin
beginx :
= x0 + xS * i;
SetLength(PointList,
0);
for j := 0 to xS - 1 do
begin
x :
= beginx + j;
for y := 0 to bmp.Height - 1 do
begin
NowColor :
= bmp.Canvas.Pixels[x, y];
if NowColor <> BColor then
begin
l :
= length(PointList);
SetLength(PointList, l
+ 1);
PointList[l].x :
= x;
PointList[l].y :
= y;
end;
end;
end;
Result :
= Result + getCode;
end;
end;

 

转载于:https://www.cnblogs.com/rogee/archive/2010/09/17/1829528.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值