欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

一個驗證碼識別的代碼

系統 2153 0

字體固定,位置固定,干擾點和字體顏色深度沒有交叉,比如下面的樣例,是我前幾天幫朋友寫投票機刷票時碰到的一個具體案例。

基本就三步,確定特征碼-分割圖片-逐個匹配,代碼很簡單,不超過100行

    using System;

using System.Collections.Generic;

using System.Text;

using System.Drawing;

namespace BmpNumber

{

    class Number

    {

        //數字特征庫

       static int[,] _num0 = new int[7, 10] { { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, 

                                        { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1 }, { 1, 1, 0, 0, 0, 0, 0, 0, 1, 1 }, 

                                        { 1, 1, 1, 0, 0, 0, 0, 1, 1, 1 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0 } };

        static int[,] _num1 = new int[7, 10] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, 

                                        { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 

                                        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };

        static int[,] _num2 = new int[7, 10] { { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1 }, { 0, 1, 1, 1, 0, 0, 0, 1, 1, 1 }, 

                                        { 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 }, { 1, 1, 0, 0, 0, 1, 1, 0, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 1, 1, 1, 0, 0, 0, 1, 1 }, { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1 } };

        static int[,] _num3 = new int[7, 10] { { 0, 0, 1, 0, 0, 0, 1, 1, 0, 0 }, { 0, 1, 1, 0, 0, 0, 1, 1, 1, 0 }, 

                                        { 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 }, { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, { 0, 1, 1, 1, 0, 1, 1, 1, 0, 0 } };

        static int[,] _num4 = new int[7, 10] { { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 }, { 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 }, 

                                        { 0, 0, 1, 1, 1, 0, 1, 1, 0, 0 }, { 0, 1, 1, 0, 0, 0, 1, 1, 0, 0 }, 

                                        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 } };

        static int[,] _num5 = new int[7, 10] { { 0, 0, 0, 1, 1, 1, 0, 1, 1, 0 }, { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 }, 

                                        { 1, 1, 1, 1, 1, 0, 0, 0, 1, 1 }, { 1, 1, 0, 1, 1, 0, 0, 0, 1, 1 },

                                        { 1, 1, 0, 1, 1, 0, 0, 0, 1, 1 }, { 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 }, { 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 } };

        static int[,] _num6 = new int[7, 10] { { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, 

                                        { 1, 1, 1, 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 1, 0, 1, 1, 1 }, { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }, { 0, 1, 1, 0, 0, 1, 1, 1, 1, 0 } };

        static int[,] _num7 = new int[7, 10] { { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, 

                                        { 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 }, { 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 }, 

                                        { 1, 1, 0, 1, 1, 1, 0, 0, 0, 0 }, { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 } };

        static int[,] _num8 = new int[7, 10] { { 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 } };

        static int[,] _num9 = new int[7, 10] { { 0, 1, 1, 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, { 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 }, 

                                        { 1, 1, 0, 0, 1, 1, 0, 1, 1, 1 }, { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, { 0, 0, 1, 1, 1, 1, 1, 1, 0, 0 } };



        static private int[,] getNum(Bitmap bmp, int index)

        {

            //分割圖片

            int[,] _num = new int[7, 10];

            for (int i = index * 10 + 2; i < index * 10 + 9; i++)

            {

                for (int j = 6; j < 16; j++)

                {

                    Color c = bmp.GetPixel(i, j);

                    if (c.R < 100)

                    {

                        _num[i - 2 - index * 10, j - 6] = 1;

                    }

                }

            }

            return _num;

        }



        static private int CheckNumber(int[,] number)

        {

            if (CheckNumber(_num0, number) == true) return 0;

            if (CheckNumber(_num1, number) == true) return 1;

            if (CheckNumber(_num2, number) == true) return 2;

            if (CheckNumber(_num3, number) == true) return 3;

            if (CheckNumber(_num4, number) == true) return 4;

            if (CheckNumber(_num5, number) == true) return 5;

            if (CheckNumber(_num6, number) == true) return 6;

            if (CheckNumber(_num7, number) == true) return 7;

            if (CheckNumber(_num8, number) == true) return 8;

            if (CheckNumber(_num9, number) == true) return 9;

            return 6;

        }

        static private bool CheckNumber(int[,] dic, int[,] number)

        {

            //逐個匹配

            for (int i = 0; i < 7; i++)

            {

                for (int j = 0; j < 10; j++)

                {

                    if (dic[i, j] == 1 && number[i, j] != 1)

                    {

                        return false;

                    }

                }



            }

            return true;

        }



        static public string getNumber(Bitmap bmp)

        {

            //調用

            string str = "";

            for (int i = 0; i <= 3; i++)

            {

                int[,] number = getNum(bmp, i);



                int m = CheckNumber(number);

                str += m.ToString();

            }

            return str;

        }

    }

}


  

用以下代碼調用就可以看到輸出結果為9637了,這個識別代碼沒有用到任何高級算法,所以也只能識別初級的驗證碼,但是對特征庫擴展之后也可以識別出規范的字母。

    System.Net.WebClient wb = new System.Net.WebClient();

            byte[] b=wb.DownloadData("http://p.blog.csdn.net/images/p_blog_csdn_net/jinjazz/355056/o_rrr.bmp");



            System.IO.MemoryStream ms=new System.IO.MemoryStream(b);



            System.Drawing.Bitmap bmp = new Bitmap(ms);



            string str = BmpNumber.Number.getNumber(bmp);

            Console.WriteLine(str);
  

一個驗證碼識別的代碼


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久99免费观看 | 麻豆精品传媒一二三区在线视频 | 成人午夜视频网站 | 日本人丰满xxxxhd | 91视频免费网址 | 大学生一级毛片全黄毛片黄 | 亚洲成人一区二区三区 | 色花堂国产精品第一页 | 91久久精品日日躁夜夜躁国产 | 98香蕉草草视频在线精品看 | 久久国内精品 | 97久久精品一区二区三区观看 | 日韩欧美在线一区二区三区 | 欧美黑人伦理 | 亚洲99影视一区二区三区 | 亚洲黄页 | 欧美爽爽爽高清免费视频 | 天天操天天射天天操 | 日韩在线中文字幕 | 精品国产不卡一区二区三区 | 且试天下修久容 | 电家庭影院午夜 | 国产一区亚洲一区 | 日韩三极| 国产在线观看www鲁啊鲁免费 | 亚洲欧美在线观看视频 | 久久香蕉综合精品国产 | 欧美久久xxxxxx影院 | 深爱婷婷 | 久久久噜噜噜久久中文字幕色伊伊 | 日本超碰 | 亚洲成人精品 | 日本道专区无码中文字幕 | 国产精品人成福利视频 | 国产福利一区二区 | 91短视频在线高清hd | 亚洲精品久久久 | 国产欧美精品一区二区三区 | 欧美日韩高清不卡一区二区三区 | 亚洲精品黄色 | 两女互慰磨豆腐视频在线观看 |