• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
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;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi串口通讯的监听发布时间:2022-07-18
下一篇:
Delphi中播放wav发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap