验证码 -图形图像识别的算法。http://blog.csdn.net/xtalk2008/archive/2007/11/01/1861310.aspx...
图像经过处理后,还需要进行分割,才能进行比较或识别,下面就是图像分割的算法
原始图
分割后的图形
12345678
图像分割代码如下
TImageInfo = record
Bmp: TBitmap;
Rect: TRect;
end;
pImageInfo = ^TImageInfo;
function BTSegment(Bmp: TBitmap; CType, MaxValue, MinValue: Integer): TList;
procedure Connect1(tbmp: tbitmap; x, y: integer; var _xmin, _xmax, _ymin, _ymax: integer; Color: TColor = 1);
begin
tbmp.PixelFormat := pf24bit;
tbmp.canvas.pixels[x,y] := Color;
_xmin := min(x, _xmin); _xmax := max(x, _xmax); _ymin := min(y, _ymin); _ymax := max(y, _ymax);
if tbmp.canvas.pixels[x + 1, y + 0] = ClBlack then connect1(tbmp, x + 1, y + 0, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 1, y - 1] = ClBlack then connect1(tbmp, x + 1, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 0, y - 1] = ClBlack then connect1(tbmp, x + 0, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y - 1] = ClBlack then connect1(tbmp, x - 1, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y + 0] = ClBlack then connect1(tbmp, x - 1, y + 0, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y + 1] = ClBlack then connect1(tbmp, x - 1, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 0, y + 1] = ClBlack then connect1(tbmp, x + 0, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 1, y + 1] = ClBlack then connect1(tbmp, x + 1, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
end;
procedure Connect2(tbmp: tbitmap; x, y: integer; var _xmin, _xmax, _ymin, _ymax: integer; Color: TColor = 1);
begin
tbmp.PixelFormat := pf24bit;
tbmp.canvas.pixels[x,y] := Color;
_xmin := min(x, _xmin); _xmax := max(x, _xmax); _ymin := min(y, _ymin); _ymax := max(y, _ymax);
if tbmp.canvas.pixels[x + 0, y + 2] = ClBlack then connect2(tbmp, x + 0, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y + 2] = ClBlack then connect2(tbmp, x - 2, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y + 2] = ClBlack then connect2(tbmp, x - 1, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 1, y + 2] = ClBlack then connect2(tbmp, x + 1, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y + 2] = ClBlack then connect2(tbmp, x + 2, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y + 1] = ClBlack then connect2(tbmp, x + 2, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y + 0] = ClBlack then connect2(tbmp, x + 2, y + 0, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y - 1] = ClBlack then connect2(tbmp, x + 2, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y - 2] = ClBlack then connect2(tbmp, x + 2, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 1, y - 2] = ClBlack then connect2(tbmp, x + 1, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 0, y - 2] = ClBlack then connect2(tbmp, x + 0, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y - 2] = ClBlack then connect2(tbmp, x - 1, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y - 2] = ClBlack then connect2(tbmp, x - 2, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y - 1] = ClBlack then connect2(tbmp, x - 2, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y - 0] = ClBlack then connect2(tbmp, x - 2, y - 0, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y + 1] = ClBlack then connect2(tbmp, x - 2, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
end;
procedure Connect3(tbmp: tbitmap; x, y: integer; var _xmin, _xmax, _ymin, _ymax: integer; Color: TColor = 1);
begin
tbmp.PixelFormat := pf24bit;
tbmp.canvas.pixels[x,y] := Color;
_xmin := min(x, _xmin); _xmax := max(x, _xmax); _ymin := min(y, _ymin); _ymax := max(y, _ymax);
if tbmp.canvas.pixels[x - 3, y + 3] = ClBlack then Connect3(tbmp, x - 3, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y + 3] = ClBlack then Connect3(tbmp, x - 2, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y + 3] = ClBlack then Connect3(tbmp, x - 1, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 0, y + 3] = ClBlack then Connect3(tbmp, x - 0, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 1, y + 3] = ClBlack then Connect3(tbmp, x + 1, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y + 3] = ClBlack then Connect3(tbmp, x + 2, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y + 3] = ClBlack then Connect3(tbmp, x + 3, y + 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 3, y - 3] = ClBlack then Connect3(tbmp, x - 3, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 2, y - 3] = ClBlack then Connect3(tbmp, x - 2, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 1, y - 3] = ClBlack then Connect3(tbmp, x - 1, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 0, y - 3] = ClBlack then Connect3(tbmp, x - 0, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 1, y - 3] = ClBlack then Connect3(tbmp, x + 1, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 2, y - 3] = ClBlack then Connect3(tbmp, x + 2, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y - 3] = ClBlack then Connect3(tbmp, x + 3, y - 3, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 3, y + 2] = ClBlack then Connect3(tbmp, x - 3, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 3, y + 1] = ClBlack then Connect3(tbmp, x - 3, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 3, y + 0] = ClBlack then Connect3(tbmp, x - 3, y + 0, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 3, y - 2] = ClBlack then Connect3(tbmp, x - 3, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x - 3, y - 1] = ClBlack then Connect3(tbmp, x - 3, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y + 2] = ClBlack then Connect3(tbmp, x + 3, y + 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y + 1] = ClBlack then Connect3(tbmp, x + 3, y + 1, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y + 0] = ClBlack then Connect3(tbmp, x + 3, y + 0, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y - 2] = ClBlack then Connect3(tbmp, x + 3, y - 2, _xmin, _xmax, _ymin, _ymax, Color);
if tbmp.canvas.pixels[x + 3, y - 1] = ClBlack then Connect3(tbmp, x + 3, y - 1, _xmin, _xmax, _ymin, _ymax, Color);
end;
var
x, y, _x, _y, xmin, xmax, ymin, ymax: integer;
pII: pImageInfo;
begin
Result := TList.Create;
Bmp.PixelFormat := pf24bit;
for x := 1 to Bmp.Width - 2 do for y := 1 to Bmp.Height - 2 do
begin
if Bmp.Canvas.Pixels[x, y] <> ClBlack then Continue;
xmin := x; xmax := x; ymin := y; ymax := y;
if CType = 1 then Connect1(Bmp, x, y, xmin, xmax, ymin, ymax, 1);
if CType = 2 then Connect2(Bmp, x, y, xmin, xmax, ymin, ymax, 1);
if CType = 3 then Connect3(Bmp, x, y, xmin, xmax, ymin, ymax, 1);
if (xmax - xmin < MaxValue) and (xmax - xmin > MinValue) and (ymax - ymin < MaxValue) and (ymax - ymin > MinValue) then
begin
New(pII); pII.Bmp := TBitmap.Create; pII.Bmp.PixelFormat := pf24bit; pII.Bmp.Width := xmax - xmin + 4; pII.Bmp.Height := ymax - ymin + 4;
for _x := xmin - 2 to xmax + 2 do for _y := ymin - 2 to ymax + 2 do if bmp.Canvas.Pixels[_x, _y] = 1 then pII.Bmp.Canvas.Pixels[_x - xmin + 2, _y - ymin + 2] := ClBlack else pII.Bmp.Canvas.Pixels[_x - xmin + 2, _y - ymin + 2] := ClWhite;
pII.Rect.Left := xmin; pII.Rect.Right := xmax; pII.Rect.Top := ymin; pII.Rect.Bottom := ymax;
Result.Add(pII);
end;
end;
FreeAndNil(Bmp);
end;
转载于:https://www.cnblogs.com/linyawen/archive/2011/06/21/2086440.html
验证码 -图形图像识别的算法。http://blog.csdn.net/xtalk2008/archive/2007/11/01/1861310.aspx...相关推荐
- 控件包含代码块(即 ),因此无法修改控件集合 (转自http://blog.csdn.net/wangchao1982/archive/2007/11/19/1892472.aspx)...
相信很多朋友都遇到过这个问题,这的确是一个很古怪的东西.js在HTML页面的不同标签中,好像有不同的含义(具体我就不清楚了, 所以我就试着把js从head里拿到了body中,最后拿到了</htm ...
- http://blog.csdn.net/ramacess/archive/2009/11/15/4812012.aspx
来源 : http://blog.csdn.net/ramacess/archive/2009/11/15/4812012.aspx 目录 1.国家知识产权局的的针对性的政策.解释.通知.公告 1.官 ...
- http://blog.csdn.net/maomi01/archive/2005/11/21/533969.aspx
http://blog.csdn.net/maomi01/archive/2005/11/21/533969.aspx
- 成功的背后!(给所有IT人)(转载来自http://blog.csdn.net/ysuncn/archive/2007/10/07/1814127.aspx)
成功的背后,有着许多不为人知的故事,而正是这些夹杂着泪水和汗水的过去,才成就了一个个走向成功的普通人. 凌晨两点半,早已习惯了一个人坐在电脑前的我,望着屏幕,任思绪在暗夜的包容下静静流淌,时光仿佛 ...
- 资料(http://blog.csdn.net/bogues/archive/2005/11/22/534982.aspx)
考研英语阅读20篇精读汇粹 http://www.hjbbs.com/dispbbs.asp?boardid=20&id=271278 [网络硬盘http下载]06年北京海文政治暑期强化 张锦 ...
- 无形胜有形——0day破解组织探秘 http://blog.csdn.net/jiangtao/archive/2002/11/30/1868.aspx
又到了TT谈破解的时间了.TT记得以前有人写了一篇<WAREZ无形帝国>的文章,非常不错.不过该文对Warez以及0day的评述难免有失偏颇,TT现在就谈谈自己的看法. 首先谈谈什么是 ...
- dataGridView右键菜单并选中该行 http://blog.csdn.net/lanmao100/archive/2009/06/25/4298529.aspx...
dataGridView右键菜单并选中该行 程序代码: private void dataGridView1_CellMouseDown(object sender, DataGridViewCell ...
- Visual Studio 2010 单元测试之一---普通单元测试:http://blog.csdn.net/tjvictor/archive/2011/02/09/6175362.aspx...
本文以Visual Studio 2010为例,来介绍如何在Visual Studio里面进行单元测试. 首先来介绍普通单元测试,这是进行顺序测试.压力测试的基础.如果在Visual Studio 2 ...
- http://blog.csdn.net/KBUG/archive/2006/10/30/1357009.aspx
http://blog.csdn.net/KBUG/archive/2006/10/30/1357009.aspx
最新文章
- WebForm中DataGrid的20篇经典文章
- 一文回顾2018英特尔人工智能大会
- 自定义ClassLoader实现java应用核心逻辑模块热部署
- java,将Image变量保存成图片
- PyQt5 技术篇-通过参数控制Dialog窗口增加?问号按钮
- HDU - Reversi(dfs+水题)
- LeetCode中常用语言的一些基本方法记录
- Delphi关于记录文件的操作
- 当async/await遇上forEach
- 电商场景下,如何处理消费过程中的重复消息?
- mysql中删除数据库中的表格数据恢复_恢复从数据库中删除的表
- 代码编译方式 ant +ivy
- 10个好用的Web日志安全分析工具
- Jmeter(三十八)while控制器实现ssh三次重连
- 【C#语言学习】学习一门语言
- 2022全开源企业发卡网修复短网址等BUG_2022企业级多商户发卡平台源码
- 【弱电综合课程设计】三菱PLC经步进驱动器控制步进电机调速和正反转(硬件连接+梯形图)
- thrift开源项目研究
- IVX低代码平台开发——微信小程序实现抽奖功能
- H310_710阵列卡配置.
热门文章
- can usb tool下载_N1内置CoreELEC、安卓多系统3.9.6.3版发布,更新下载链接
- java12章_从零开始学Java 第12章 异常处理
- java array 元素的位置_java中的两种排序工具Arrays和Collections的使用
- 验证回文串Python解法
- python request下载文件_Python3.4.3使用urllib.request下载文件带进度显示
- 斯坦福的著名小兔子模型的点云数据_传统方法的点云分割以及PCL中分割模块
- html个版本间的特点,了解下什么是HTML5,他与以往的版本有什么区别 什么新元素...
- postgres 把一个表的值转成另一个表的字段名_Phoenix系列创建Phoenix映射表
- java 8 并行_Java 8新特性之 并行和并行数组(八恶人-8)
- shell 获取命令执行结果_java高并发系列 第31天:获取线程执行结果,这6种方法你都知道?...