在一些验证码相对简单的站点中,停一下,什么是简单?以我现在的图形算法修为,就是对于特定的字符,在生成时,其字符的Region应该是一样的,如(chars.bmp)图片中的6总是这个字体这个字号......
  如果是这样,算法很简单了,没有什么技术含量了。我们只须把验证码图片从左向右一列一列扫描,分隔出每个字符的RGN,然后和chars.bmp中的每个字符的RGN对比,就知道是哪个数字了。
   关键代码如下:
  

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        IniFile config = null;

        //查看两个颜色是不是一样,注意这里有一定误差也算相同
        public bool IsSameColor(Color c1, Color c2)
        {
            if (Math.Abs(c1.R - c2.R) < 10
                && Math.Abs(c1.G - c2.G) < 10
                && Math.Abs(c1.B - c2.B) < 10)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        //计算一个Region中,像素的个数
        public int RegionPointCount(Region r,int width,int height)
        
            int count = 0;
            for(int h = 0; h<width; ++h)
            {
                for(int v = 0; v< height; ++v)
                {
                    if(r.IsVisible(h,v))
                    {
                        ++count;
                    }
                }
            }

            return count;
        }
        
        //初始化每个字符的Region
        public void InitPictureCharInfo()
        {
            Bitmap bmp = (Bitmap)Bitmap.FromFile("chars.bmp");
            List<BitmapCharInfo> bcil = charRgnList;
            Region rgn = new Region();
            rgn.MakeEmpty();
            if (bmp.Height > 0 && bmp.Width > 0)
            {
                Color bkColor = bmp.GetPixel(0, 0);
                bool bInWorking = false;
                int nNextStartPos = 0;
                for (int h = 0; h < bmp.Width; ++h)
                {
                    bool bFindColor = false;
                    for (int v = 0; v < bmp.Height; ++v)
                    {
                        if (!IsSameColor(bkColor, bmp.GetPixel(h, v)))
                        {
                            rgn.Union(new Rectangle(h, v, 1, 1));
                            bFindColor = true;
                        }
                    }

                    if (bInWorking)
                    {
                        if (!bFindColor)
                        {
                            bInWorking = false;
                            rgn.Translate(-nNextStartPos, 0);
                            BitmapCharInfo bci = new BitmapCharInfo(rgn, h - nNextStartPos, bmp.Height);
                            bci.orgPos = nNextStartPos;
                            bcil.Add(bci);
                            rgn = new Region();
                            rgn.MakeEmpty();
                        }
                    }
                    else
                    {
                        if (bFindColor)
                        {
                            bInWorking = true;
                            nNextStartPos = h;
                        }
                    }
                }

                chars.AddRange("0123456789".ToCharArray());
            }
        }

        //扫描并识别验证码
        public void ScanValidCode()
        {
            Bitmap bmp = this.bmpValidCode;
            List<BitmapCharInfo> bcil = new List<BitmapCharInfo>();
            Region rgn = new Region();
            rgn.MakeEmpty();
            if (bmp.Height > 0 && bmp.Width > 0)
            {
                Color bkColor = bmp.GetPixel(0, 0);
                bool bInWorking = false;
                int nNextStartPos = 0;
                for (int h = 0; h < bmp.Width; ++h)
                {
                    bool bFindColor = false;
                    for (int v = 0; v < bmp.Height; ++v)
                    {
                        if (!IsSameColor(bkColor, bmp.GetPixel(h, v)))
                        {
                            rgn.Union(new Rectangle(h, v, 1, 1));
                            bFindColor = true;
                        }
                    }

                    if (bInWorking)
                    {
                        if (!bFindColor)
                        {
                            bInWorking = false;
                            rgn.Translate(-nNextStartPos, 0);
                            BitmapCharInfo bci = new BitmapCharInfo(rgn, h - nNextStartPos, bmp.Height);
                            bci.orgPos = nNextStartPos;
                            bcil.Add(bci);
                            rgn = new Region();
                            rgn.MakeEmpty();
                        }
                    }
                    else
                    {
                        if (bFindColor)
                        {
                            bInWorking = true;
                            nNextStartPos = h;
                        }
                    }
                }

                List<char> chs = new List<char>();

                Graphics gh = Graphics.FromImage(bmp);
                foreach (BitmapCharInfo bci in bcil)
                {
                    int minPos = -1;
                    int minLng = -1;
                    for (int i = 0; i < charRgnList.Count; ++i)
                    {
                        Region r = bci.rgn.Clone();
                        r.Union(charRgnList[i].rgn);
                        r.Exclude(bci.rgn);

                        int lng = RegionPointCount(r, bci.width, bci.height);

                        if (minLng == -1)
                        {
                            minLng = lng;
                            minPos = i;
                        }
                        else
                        {
                            if (lng < minLng)
                            {
                                minLng = lng;
                                minPos = i;
                            }
                        }


                    }

                    if (minPos != -1)
                    {
                        chs.Add(chars[minPos]);
                    }
                }

                string str = new string(chs.ToArray(), 0, chs.Count);
                //MessageBox.Show(str);
                this.currScanValidCode = str;

            }
        }

        public void GetValidCodePicture(CookieContainer cc, WebProxy wp )
        
            //this.pbValidCode.ImageLocation = this.pbValidCode.ImageLocation;
            Exception exp = null;
            for (int i = 0; i < 3; ++i)
            {
                try
                {
                    Stream s = GetDataNonProxy(this.tbValidPicUrl.Text, cc,wp);
                    Bitmap bmp = (Bitmap)Bitmap.FromStream(s);
                    s.Close();

                    bmpValidCode = bmp;

                    return;
                }
                catch (Exception ex)
                {
                    exp = ex;
                }
            }
        
            MessageBox.Show("猎取图片失败:" + exp == null?"unkown":exp.Message);
        }

        Bitmap bmpValidCode = null;
        private void btnLoadPic_Click(object sender, EventArgs e)
        {

            this.GetValidCodePicture(null,null);
            currValidCode = this.currScanValidCode;
            this.UpdateDate(false);
        }

        List<BitmapCharInfo> charRgnList = new List<BitmapCharInfo>();
        List<char> chars = new List<char>();
        private void btnInit_Click(object sender, EventArgs e)
        {
            InitPictureCharInfo();
        }



        private void btnScanValidCode_Click(object sender, EventArgs e)
        {
            ScanValidCode();
            this.currValidCode = this.currScanValidCode;
            this.UpdateDate(false);

        }

        

        string currScanValidCode;

          
          
          

        private void Form1_Load(object sender, EventArgs e)
        {
            this.UpdateDate(true);
            InitPictureCharInfo();
            config = new IniFile(Application.ExecutablePath + ".ini");
            lastPwdPosInDict = config.GetInt("Process", "PwdPostion", 0);
            InitPwdDict();
            UpdateProcessText();
        }



    }

    public class BitmapCharInfo 
    {
        public BitmapCharInfo()
        {
            this.rgn = new Region();
            this.rgn.MakeEmpty();
        }
        public BitmapCharInfo(Region r, int w, int h)
        {
            this.rgn = r;
            this.width = w;
            this.height = h;
        }
        public Region rgn;
        public int width = 0;
        public int height = 0;
        public int orgPos = 0;

    }
}

  识别效率提高的,但是局限性太高了。现在这类我网站也少得多了,现在放出来。希望抛砖引玉引出图形的高级算法来。

超级简单的Region对比识别验证码相关推荐

  1. 手写一个获取验证码的接口,超级简单

    手写一个获取验证码的接口,超级简单,觉得有用就试试吧,话不多说代码附上 private static final int VERIFY_CODE_HEIGHT = 25; //验证码高度private ...

  2. Python使用网络抓包的方式,利用超级鹰平台识别验证码登录爬取古诗文网、上篇--识别验证码

    Python使用网络抓包的方式,利用超级鹰平台识别验证码登录,<爬取古诗文网>. 上篇–识别验证码 序言: 哈喽,各位小可爱们,我又来了,这次我新学习到的内容是python爬虫识别验证码. ...

  3. 教你搭建一个花卉识别系统(超级简单)

    目录 一.开源神经网络(AlexNet) 1.获取数据集 2.神经网络模型 3.训练神经网络 4.对模型进行预测 二.花卉识别系统搭建(flask) 1.构建页面: 2.调用神经网络模型 3.系统识别 ...

  4. 最简单的python使用ddddocr模块在线识别验证码后登录

    import unittest from PIL import Image from selenium import webdriver from time import sleep import d ...

  5. 如何通过 Serverless 轻松识别验证码?

    作者 | 江昱 来源 | Serverless 公众号 前言 Serverless 概念自被提出就倍受关注,尤其是近些年来 Serverless 焕发出了前所未有的活力,各领域的工程师都在试图将 Se ...

  6. Web简单快捷的指纹识别小工具_在线指纹识别平台设计

    Web 指纹识别 本文通过分析 Web 指纹的检测对象.检测方法.检测原理及常用工具,设计了一个简易的指纹搜集脚本来协助发现新指纹,并提取了多个开源指纹识别工具的规则库并进行了规则重组,开发了一个简单 ...

  7. 使用Python+Tensorflow的CNN技术快速识别验证码

    北京 上海巡回站 | NVIDIA DLI深度学习培训 2018年1月26/1月12日 NVIDIA 深度学习学院 带你快速进入火热的DL领域 阅读全文                        ...

  8. python 基于机器学习识别验证码

    1.背景     验证码自动识别在模拟登陆上使用的较为广泛,一直有耳闻好多人在使用机器学习来识别验证码,最近因为刚好接触这方面的知识,所以特定研究了一番.发现网上已有很多基于machine learn ...

  9. python 识别图形验证码_Python图片验证码降噪处理实例!此乃识别验证码神技!...

    图片验证码算是网络数据采集上的一道拦路虎,虽然有诸多公开的ORC接口.云打码平台,一旦大规模应用起来,还是内部写程序进行识别处理比较好. 而自己写代码进行识别的话,又有很多种方案,比如最近火热的神经网 ...

最新文章

  1. 视频格式转换工具使用
  2. 【论文阅读】开放域问答论文总结,文本召回与问答的另一种思路
  3. linux下ffmpeg编译成so文件,一、ffmpeg编译成android使用的so库
  4. VMware虚拟机安装
  5. 【转载】安装程序无法复制文件CONVLOG.EX
  6. Python办公自动化|光速对比并提取两份Word/Excel中的不同元素
  7. redis缓存失效及解决方案
  8. Laravel核心解读--观察者模式
  9. 小量数据和海量数据分页显示存储过程
  10. python对大小写敏感吗_python大小写不敏感吗
  11. AI说,它可以把你变成个游戏 | 3D人体模型 · CVPR
  12. Excel显示完整的年月日乱码解决方法
  13. springboot框架学习理解下
  14. android安卓源码海量项目合集打包-1
  15. SQL Server 添加字段 修改字段 删除字段 语句
  16. Blender 常用快捷键记录 (二)
  17. 【锂电】锂电工艺大全
  18. iSCSI发起程序找不到iSCSI_Software_Target_33服务的虚拟磁盘解决办法
  19. 厘米与像素的单位转换
  20. sql优化(面试必问一)

热门文章

  1. udt编写高性能服务器,基于UDT协议的Oracle数据库远程备份的设计和实现
  2. sql删除主键_产品经理的第一节SQL课——ID到底是干什么的?!
  3. dplyr | 数据处理函数的功能速查!dplyr包中的十类操作函数汇总(下篇)
  4. C语言分支结构while,C语言学习:分支结构和循环结构的总结(收藏)
  5. 服务器一般在什么位置,云服务器比较普通服务器差异在哪里
  6. 学校机房为什么要穿鞋套?
  7. Web前端求职必备 常见前端面试题汇总(二)
  8. 华为mate10手机听筒测试软件,华为mate 10功能说:这几个设置,让你通话体验直线上升,简直了!...
  9. python queue函数_Python模块:queue
  10. 西门子real是什么数据类型_如何实现西门子新一代精智屏及基本屏与 S120 的直接通讯...