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

2023-05-16


  
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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 我可以访问 TBits 内部位图吗?

    In particular i want to preset desired size fetch a bitmap from external source and then work with data in classy object
  • 如何隐藏 WebBrowser 直到网站完成加载/下载过程?

    我想知道我该如何隐藏WebBrowser直到网站加载过程完成 另外 我使用 Panel1 和WebBrowser在它的上面 为什么 好吧 这样 我可以完全像我想要的 WebBrowser 一样设置 Panel1 的大小和位置 然后将 Web
  • 开发 Delphi Windows 7 应用程序的规则 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 在哪里可以找到开发适用于 Windows 7 的 Delphi 应用程序时应遵循的最佳规则集 Marco 最近发表了 2 篇关于此主题的帖
  • 可以在delphi数据集中创建一个假数据字段吗?

    我想在 DataSet 不是 ClientDataSet 中创建一个 假 数据字段 该字段不应存储在数据库中 它不是计算字段 应允许用户输入输入数据 该字段具有业务逻辑含义 因此用户更新其值后应该更新其他字段 使用 OnFieldChang
  • delphi中生成随机数

    我想在delphi中创建一个随机数并将其分配给文件作为文件名 我设法做到了这一点 但是当我单击按钮生成数字时 它总是以 0 开头 知道如何修复它 procedure TForm1 Button1Click Sender TObject va
  • Indy FTP 传输类型

    我正在使用 IdFTP Indy 10 组件从远程位置下载一些文件 zip 和 txt 在获取每个文件之前 我将 TransferType 设置为二进制 IdFTP TransferType ftBinary IdFTP Get ASour
  • Delphi - 将字符串从 UTF-8 转换回来

    我在将 UTF 8 编码字符串转换回 delphi 可用的字符串时遇到问题 该应用程序是用 XE8 编写的 并部署在 Windows 和 OSX 上 该应用程序分别在 Windows 和 OSX 上使用 LimeLM API dll 和 d
  • Winform 没有.NET 框架?

    我必须创建一些表单并将其作为直接 EXE 提供 而不是安装程序 它安装 NET 框架 最终用户对此不满意 他们想要可以直接打开和工作的东西 我知道它可以作为网络完成 但我正在寻找 winforms 吗 请建议哪种工具 技术可以处理这个问题
  • 能否从 Vista Shell 获取 48x48 或 64x64 图标?

    如果 Vista Shell 中存在 48x48 或 64x64 图标 如何使用 SHGetFileInfo 获取在 TImage 中显示图标的句柄 我想从图像列表中选择一个代表文件夹路径的图标 并在 Timage 中显示 48x48 或
  • 为应用程序启用主题

    我有一个旧的应用程序 在Win XP中的delphi 7中启动 现在我正在使用delphi 2009 win Vista 如果我开始一个新项目 所有按钮都有一个圆形边缘 但在我的旧应用程序中 所有按钮都有 方形 形状的外观 有什么设置我错过
  • 如何允许表单接受文件删除而不处理 Windows 消息?

    在 Delphi XE 中 我可以允许我的表单接受文件 拖放 但不必处理裸窗口消息吗 您不需要处理消息来实现这一点 你只需要实施IDropTarget并打电话RegisterDragDrop RevokeDragDrop 这真的非常非常简单
  • 使用 StretchDIBits 使用 Delphi 6 处理条形码图像 - 输出中缺少条形线

    我的应用程序是在 Delphi 6 中开发的 由于后台处理和大量数据 它消耗大约 60MB 120MB 物理内存 这是一个资源密集型应用程序 该应用程序的功能之一是在进行某些处理后创建条形码图像 如果用户继续生成条形码 那么至少十分之一的条
  • Delphi - 相当于C#的三元运算符? [复制]

    这个问题在这里已经有答案了 可能的重复 Delphi 中是否存在或者将来是否存在条件运算符 https stackoverflow com questions 2108609 is there or is there ever going
  • 如何将FireMonkey表单无缝嵌入VCL表单中?

    我使用了中描述的技巧这个问题 https stackoverflow com questions 7315050 delphi xe2 possible to instantiate a firemonkey form in vcl app
  • 我应该害怕使用 UDP 进行客户端/服务器广播通话吗?

    我在过去的两天里阅读了每一篇StackOverflow问题和答案 以及googling当然 关于印地TCP and UDP协议 以便决定在我的用户应用程序和 Windows 服务之间的通信方法中应该使用哪一种 从我目前所看到的来看 UDP是
  • Delphi DataSnap REST 服务器从 TStream 返回 JSON 数组,而不是二进制

    我有一个与 Android 客户端通信的 REST 服务器 我将它从 XE3 ish 升级到 Berlin 其中一个服务器方法返回一个包含 jpeg 的 TStream 并且工作得很好 很高兴将图像作为二进制图像返回 升级到 Berlin
  • 以 png 格式剪辑幻灯片 (Delphi 2010)

    I have a filmstrip of images in png format like this 我想知道如何剪辑每个图像并将这些图像放入 TImageList 控件中 并始终保留透明度 EDIT 是的 在设计时 RRUZ 提到的技
  • 在TImageViewer中,如何获取用户点击图片的位置?

    在TImageViewer控件中 用户可以缩放或平移图片 我的问题是 当用户点击图片时 如何获取用户在图片上的点击位置 尤其是用户可以对图片进行放大 缩小或平移之后 如何获取对应的图片点击位置呢 As shown below How to
  • 使用 TStringList 的分隔符解析字符串,似乎也解析空格(Delphi)

    我有一个简单的字符串 由某个字符分隔 比如说逗号 我应该能够创建一个 TStringList 并将其分隔符设置为逗号 然后将 DelimitedText 设置为我想要解析的文本 并且应该自动解析它 问题是 当我查看输出时 它还包含空格作为分
  • Delphi 5 的哈希表实现 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 您知道 Delphi 5 的良好且免费的哈希表实现吗 我需要在哈希表中组织大量数据 并且我有点担心在网

随机推荐