QQ验证码识别源代码(DOT NET1.1)
来源:互联网 发布:linux top nic 编辑:程序博客网 时间:2024/06/10 11:57
C#代码:
using System;namespace QQ{/// <summary>/// yzm 的摘要说明。/// </summary>public class yzm{public yzm(public System.Drawing.Bitmap pic){this.bp = pic;}/// <summary>/// 将一个int值存入到4个字节的字节数组(从高地址开始转换,最高地址的值以无符号整型参与"与运算")/// </summary>/// <param name="thevalue">要处理的int值</param>/// <param name="thebuff">存放信息的字符数组</param>public static void getbytesfromint(int thevalue, byte[] thebuff){long v1=0; long v2=0; long v3=0; long v4=0;uint b1=(uint)4278190080; uint b2=(uint)16711680; uint b3=(uint)65280; uint b4=(uint)255;v1=thevalue & b1;v2=thevalue & b2;v3=thevalue & b3;v4=thevalue & b4;thebuff[0]=(byte)(v1>>24);thebuff[1]=(byte)(v2>>16);thebuff[2]=(byte)(v3>>8);thebuff[3]=(byte)v4;}/// <summary>/// 将一个ushort值存入到2个字节的字节数组(从高地址开始转换,最高地址的值以无符号整型参与"与运算")/// </summary>/// <param name="thevalue">要处理的ushort值</param>/// <param name="thebuff">存放信息的字符数组</param>public static void getbytesfromushort(ushort thevalue, byte[] thebuff){ushort v1=0; ushort v2=0;ushort b1=(ushort)65280; ushort b2=(ushort)255;v1=(ushort)(thevalue & b1);v2=(ushort)(thevalue & b2); thebuff[0]=(byte)(v1>>8);thebuff[1]=(byte)(v2); }/// <summary>/// 将4个字节的字节数组转换成一个int值/// </summary>/// <param name="thebuff">字符数组</param>/// <returns></returns>public static int getintfrombyte(byte[] thebuff){int jieguo=0;long mid=0;long m1=0; long m2=0; long m3=0; long m4=0;m1=(thebuff[0]<<24);m2=(thebuff[1]<<16);m3=(thebuff[2]<<8);m4=thebuff[3];mid=m1+m2+m3+m4;jieguo=(int)mid;return jieguo;}/// <summary>/// 将2个字节的字节数组转换成一个ushort值/// </summary>/// <param name="thebuff">字符数组</param>/// <returns></returns>public static ushort getushortfrombyte(byte[] thebuff){int jieguo1=0;jieguo1=(thebuff[0]<<8)+thebuff[1];ushort jieguo=(ushort)jieguo1;return jieguo;}/// <summary>/// 将内存中的数据写入硬盘(保存特征库)/// </summary>/// <param name="thefile">保存的位置</param>public static void writetofile(string thefile){System.IO.FileStream fs = new System.IO.FileStream(thefile,System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.ReadWrite);byte[] buff0=new byte[4];getbytesfromint(datanum,buff0);fs.Write(buff0,0,4);for(int ii=0;ii<datanum;ii++){for(int jj=0;jj<20;jj++){byte[] buff=new byte[2];getbytesfromushort(datap[ii,jj],buff);fs.Write(buff,0,2);} fs.WriteByte(dataxy[ii,0]);fs.WriteByte(dataxy[ii,1]);fs.WriteByte(datachar[ii]);}fs.Close();}/// <summary>/// 从文件中读取信息,并保存在内存中相应的位置/// </summary>/// <param name="thefile">特征库文件</param>public static void readfromfile(string thefile){int allnum=0;byte[] buff=new byte[4];System.IO.FileStream fs = new System.IO.FileStream(thefile,System.IO.FileMode.Open,System.IO.FileAccess.Read);fs.Read(buff,0,4);allnum=getintfrombyte(buff);byte[] buff0=new byte[2];for(int ii=0;ii<allnum;ii++){for(int jj=0;jj<20;jj++){fs.Read(buff0,0,2);datap[ii,jj]=getushortfrombyte(buff0);}fs.Read(buff0,0,1);dataxy[ii,0]=buff0[0];fs.Read(buff0,0,1);dataxy[ii,1]=buff0[0];fs.Read(buff0,0,1);datachar[ii]=buff0[0];}datanum=allnum;fs.Close();}/// <summary>/// 验证码图片/// </summary>public System.Drawing.Bitmap bp =new System.Drawing.Bitmap(49,20);/// <summary>/// 特征库的长度/// </summary>public static int datanum=0;/// <summary>/// 特征库数据/// </summary>public static ushort[,] datap=new ushort[100000,20];/// <summary>/// 长度与高度/// </summary>public static byte[,] dataxy=new byte[100000,2];/// <summary>/// 对应的字符/// </summary>public static byte[] datachar=new byte[100000];/// <summary>/// 等待处理的数据/// </summary>public ushort[] datapic=new ushort[20];/// <summary>/// 有效长度/// </summary>public byte xlpic=0;/// <summary>/// 有效宽度/// </summary>public byte ylpic=0;/// <summary>/// 检索特征库中存在的记录/// </summary>public string getchar(){//如果查找不到,就返回空串string jieguo=""; for(int ii=0;ii<datanum;ii++){//统计一共有多少行的像素有差异,如果在4行以内就认为是存在该记录//这种方法比较原始,但比较适合多线程时的运行,因为程序只进行简单的逻辑比较//如果能够收集更多的特征库,识别率可以达到80%以上//(此时可能需要将特征库的容量提高到15W个或以上)//当然也可以改进品配算法(如使用关键点品配),以用较少的特征库达到较高的识别率,但//那样有比较大的机会造成识别错误并且多线程时占用较多CPU时间。int notsamenum=0;if(dataxy[ii,0]!=xlpic || dataxy[ii,1]!=ylpic){continue;}for(int jj=0;jj<20;jj++){if(datap[ii,jj]!=datapic[jj]){notsamenum++;}}if(notsamenum<4){char cj=(char)datachar[ii];return cj.ToString();}}return jieguo;}/// <summary>/// 检查特征库中是否已经存在相关记录/// </summary>bool ischardatain(){bool jieguo=false;for(int ii=0;ii<datanum;ii++){//统计一共有多少行的像素有差异,如果在4行以内就认为是存在该记录//这种方法比较原始,但比较适合多线程时的运行,因为程序只进行简单的逻辑比较//如果能够收集更多的特征库,识别率可以达到80%以上//(此时可能需要将特征库的容量提高到15W个或以上)//当然也可以改进品配算法(如使用关键点品配),以用较少的特征库达到较高的识别率,但//那样有比较大的机会造成识别错误并且多线程时占用较多CPU时间。int notsamenum=0;if(System.Math.Abs(dataxy[ii,0]-xlpic)>1 || System.Math.Abs(dataxy[ii,1]-ylpic)>1){continue;}for(int jj=0;jj<20;jj++){if(datap[ii,jj]!=datapic[jj]){notsamenum++;}} if(notsamenum<4){ string asdasd=((char)datachar[ii]).ToString();return true;}}return jieguo;}/// <summary>/// 添加到特征库中,并暂时将对应的字符置为空格以待人工识别/// </summary>void adddatawithnullchar(){if(this.ischardatain()){return;}for(int ii=0;ii<20;ii++){datap[datanum,ii]=this.datapic[ii];}//暂时将对应的字符置为空格以待人工识别datachar[datanum]=32;dataxy[datanum,0]=this.xlpic;dataxy[datanum,1]=this.ylpic;datanum++;}/// <summary>/// 检查验证码图片是否能分成4个部分,如果可以就检查4个字符在特征库中是否已经存在,如果不存在,/// 就添加到特征库中,并暂时将对应的字符置为空格以待人工识别/// </summary>public void writetodata(){bool[,] picpixel=new bool[49,20];for(int ii=0;ii<49;ii++){for(int jj=0;jj<20;jj++){if(bp.GetPixel(ii,jj).GetBrightness()<0.999){picpixel[ii,jj]=true;}}}int[] index=new int[8];int indexnum=0;bool black=false;for(int ii=0;ii<49;ii++){bool haveblack=false;for(int jj=0;jj<20;jj++){if(picpixel[ii,jj]){haveblack=true;break;}}if(haveblack && black==false){index[indexnum]=ii;indexnum++;black=true;}if(!haveblack && black){index[indexnum]=ii;indexnum++;black=false;}}if(indexnum<7){return;}if(indexnum==7){index[7]=49;}//****for(int ii=0;ii<4;ii++){int x1=index[ii*2];int x2=index[ii*2+1];int y1=0,y2=19;bool mb=false;for(int jj=0;jj<20;jj++){ for(int kk=x1;kk<x2;kk++){if(picpixel[kk,jj]){mb=true;break;}}if(mb){y1=jj;break;}}mb=false;for(int jj=19;jj>=0;jj--){ for(int kk=x1;kk<x2;kk++){if(picpixel[kk,jj]){mb=true;break;}}if(mb){y2=jj;break;}}//**以上是获取有效区域的范围for(int jj=0;jj<20;jj++){this.datapic[jj]=0;this.datapic[jj]=0;}this.xlpic=(byte)(x2-x1);//如果字符宽度超过16个像素就不予处理if(xlpic>16){continue;}this.ylpic=(byte)(y2-y1+1);int ys=-1; ushort[] addin=new ushort[]{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};for(int jj=y1;jj<=y2;jj++){ys++;int xs=-1;for(int kk=x1;kk<x2;kk++){xs++;if(picpixel[kk,jj]){this.datapic[ys]=(ushort)(this.datapic[ys]+addin[xs]);}} } this.adddatawithnullchar();}//****}/// <summary>/// 识别图片/// </summary>/// <returns>返回识别结果(如果返回的字符串长度小于4就说明识别失败)</returns>public string ocrpic(){string jieguo="";bool[,] picpixel=new bool[49,20];for(int ii=0;ii<49;ii++){for(int jj=0;jj<20;jj++){if(bp.GetPixel(ii,jj).GetBrightness()<0.999){picpixel[ii,jj]=true;}}}int[] index=new int[8];int indexnum=0;bool black=false;for(int ii=0;ii<49;ii++){bool haveblack=false;for(int jj=0;jj<20;jj++){if(picpixel[ii,jj]){haveblack=true;break;}}if(haveblack && black==false){index[indexnum]=ii;indexnum++;black=true;}if(!haveblack && black){index[indexnum]=ii;indexnum++;black=false;}}if(indexnum<7){return jieguo;}if(indexnum==7){index[7]=49;}//****for(int ii=0;ii<4;ii++){int x1=index[ii*2];int x2=index[ii*2+1];int y1=0,y2=19;bool mb=false;for(int jj=0;jj<20;jj++){ for(int kk=x1;kk<x2;kk++){if(picpixel[kk,jj]){mb=true;break;}}if(mb){y1=jj;break;}}mb=false;for(int jj=19;jj>=0;jj--){ for(int kk=x1;kk<x2;kk++){if(picpixel[kk,jj]){mb=true;break;}}if(mb){y2=jj;break;}}//**以上是获取有效区域的范围for(int jj=0;jj<20;jj++){this.datapic[jj]=0;this.datapic[jj]=0;}this.xlpic=(byte)(x2-x1);//如果字符宽度超过16个像素就不予处理if(xlpic>16){continue;}this.ylpic=(byte)(y2-y1+1);int ys=-1; ushort[] addin=new ushort[]{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};for(int jj=y1;jj<=y2;jj++){ys++;int xs=-1;for(int kk=x1;kk<x2;kk++){xs++;if(picpixel[kk,jj]){this.datapic[ys]=(ushort)(this.datapic[ys]+addin[xs]);}} } jieguo=jieguo+this.getchar();}return jieguo;}}}
VB.NET代码:Imports System '/ <summary> '/ yzm 的摘要说明。 '/ </summary> Public Class yzm Public Sub New(__unknown As __unknown) Dim pic As System.Drawing.Bitmap ' 'ToDo: Error processing original source shown below ' ' '------------^--- Syntax error: 'identifier' expected ' 'ToDo: Error processing original source shown below ' ' '--------------------------------------------^--- Syntax error: ';' expected If (True) Then Me.bp = pic End If '/ <summary> '/ 将一个int值存入到4个字节的字节数组(从高地址开始转换,最高地址的值以无符号整型参与"与运算") '/ </summary> '/ <param name="thevalue">要处理的int值</param> '/ <param name="thebuff">存放信息的字符数组</param> Dim getbytesfromint As ' 'ToDo: Error processing original source shown below ' ' '---------------^--- GenCode(token): unexpected token type Dim thebuff() As Byte ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '-----------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------------------------^--- Syntax error: '.' expected ' 'ToDo: Error processing original source shown below ' ' '------------------------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------------------------------------------------^--- Syntax error: ';' expected If (True) Then Dim v1 As Long = 0 Dim v2 As Long = 0 Dim v3 As Long = 0 Dim v4 As Long = 0 Dim b1 As System.UInt32 = CType(, System.UInt32) 'ToDo: Unsigned Integers not supported ' 'ToDo: Error processing original source shown below ' ' '---------------^--- Unable to cast object of type 'CSToVBLib.UIntToken' to type 'CSToVBLib.IntToken'. 'ToDo: Unsigned Integers not supported Dim b2 As System.UInt32 = CType(16711680, System.UInt32) 'ToDo: Unsigned Integers not supported 'ToDo: Unsigned Integers not supported Dim b3 As System.UInt32 = CType(65280, System.UInt32) 'ToDo: Unsigned Integers not supported 'ToDo: Unsigned Integers not supported Dim b4 As System.UInt32 = CType(255, System.UInt32) 'ToDo: Unsigned Integers not supported 'ToDo: Unsigned Integers not supported v1 = thevalue And b1 v2 = thevalue And b2 v3 = thevalue And b3 v4 = thevalue And b4 thebuff(0) = CByte(Machine.Shift.Right(v1, 24)) thebuff(1) = CByte(Machine.Shift.Right(v2, 16)) thebuff(2) = CByte(Machine.Shift.Right(v3, 8)) thebuff(3) = CByte(v4) End If '/ <summary> '/ 将一个ushort值存入到2个字节的字节数组(从高地址开始转换,最高地址的值以无符号整型参与"与运算") '/ </summary> '/ <param name="thevalue">要处理的ushort值</param> '/ <param name="thebuff">存放信息的字符数组</param> Dim getbytesfromushort As ' 'ToDo: Error processing original source shown below ' ' '---------------^--- GenCode(token): unexpected token type Dim thebuff() As Byte ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------------------------------^--- Syntax error: '.' expected ' 'ToDo: Error processing original source shown below ' ' '------------------------------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------------------------------------------------------^--- Syntax error: ';' expected If (True) Then Dim v1 As System.UInt16 = 0 'ToDo: Unsigned Integers not supported Dim v2 As System.UInt16 = 0 'ToDo: Unsigned Integers not supported Dim b1 As System.UInt16 = CType(65280, System.UInt16) 'ToDo: Unsigned Integers not supported 'ToDo: Unsigned Integers not supported Dim b2 As System.UInt16 = CType(255, System.UInt16) 'ToDo: Unsigned Integers not supported 'ToDo: Unsigned Integers not supported v1 = CType(thevalue And b1, System.UInt16) 'ToDo: Unsigned Integers not supported v2 = CType(thevalue And b2, System.UInt16) 'ToDo: Unsigned Integers not supported thebuff(0) = CByte(Machine.Shift.Right(v1, 8)) thebuff(1) = CByte(v2) End If '/ <summary> '/ 将4个字节的字节数组转换成一个int值 '/ </summary> '/ <param name="thebuff">字符数组</param> '/ <returns></returns> Dim getintfrombyte As Integer Byte() ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '---------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '--------------------------------------^--- Syntax error: '.' expected ' 'ToDo: Error processing original source shown below ' ' '-----------------------------------------^--- Syntax error: ')' expected ' 'ToDo: Error processing original source shown below ' ' '------------------------------------------------^--- Syntax error: ';' expected If (True) Then Dim jieguo As Integer = 0 Dim mid As Long = 0 Dim m1 As Long = 0 Dim m2 As Long = 0 Dim m3 As Long = 0 Dim m4 As Long = 0 m1 = Machine.Shift.Left(thebuff(0), 24) m2 = Machine.Shift.Left(thebuff(1), 16) m3 = Machine.Shift.Left(thebuff(2), 8) m4 = thebuff(3) mid = m1 + m2 + m3 + m4 jieguo = CInt(mid) Return jieguo End If '/ <summary> '/ 将2个字节的字节数组转换成一个ushort值 '/ </summary> '/ <param name="thebuff">字符数组</param> '/ <returns></returns> Dim getushortfrombyte As System.UInt16 'ToDo: Unsigned Integers not supported Byte() ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '---------------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '--------------------------------------------^--- Syntax error: '.' expected ' 'ToDo: Error processing original source shown below ' ' '-----------------------------------------------^--- Syntax error: ')' expected ' 'ToDo: Error processing original source shown below ' ' '------------------------------------------------------^--- Syntax error: ';' expected If (True) Then Dim jieguo1 As Integer = 0 jieguo1 = Machine.Shift.Left(thebuff(0), 8) + thebuff(1) Dim jieguo As System.UInt16 = CType(jieguo1, System.UInt16) 'ToDo: Unsigned Integers not supported 'ToDo: Unsigned Integers not supported Return jieguo End If '/ <summary> '/ 将内存中的数据写入硬盘(保存特征库) '/ </summary> '/ <param name="thefile">保存的位置</param> Dim writetofile As ' 'ToDo: Error processing original source shown below ' ' '---------------^--- GenCode(token): unexpected token type ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '-------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '---------------------------------------^--- Syntax error: '.' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------------------------------^--- Syntax error: ';' expected If (True) Then Dim fs As New System.IO.FileStream(thefile, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite) Dim buff0(4) As Byte getbytesfromint(datanum, buff0) fs.Write(buff0, 0, 4) Dim ii As Integer For ii = 0 To datanum - 1 Dim jj As Integer For jj = 0 To 19 Dim buff(2) As Byte getbytesfromushort(datap(ii, jj), buff) fs.Write(buff, 0, 2) Next jj fs.WriteByte(dataxy(ii, 0)) fs.WriteByte(dataxy(ii, 1)) fs.WriteByte(datachar(ii)) Next ii fs.Close() End If '/ <summary> '/ 从文件中读取信息,并保存在内存中相应的位置 '/ </summary> '/ <param name="thefile">特征库文件</param> Dim readfromfile As ' 'ToDo: Error processing original source shown below ' ' '---------------^--- GenCode(token): unexpected token type ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------------------------^--- Syntax error: '.' expected ' 'ToDo: Error processing original source shown below ' ' '-----------------------------------------------^--- Syntax error: ';' expected If (True) Then Dim allnum As Integer = 0 Dim buff(4) As Byte Dim fs As New System.IO.FileStream(thefile, System.IO.FileMode.Open, System.IO.FileAccess.Read) fs.Read(buff, 0, 4) allnum = getintfrombyte(buff) Dim buff0(2) As Byte Dim ii As Integer For ii = 0 To allnum - 1 Dim jj As Integer For jj = 0 To 19 fs.Read(buff0, 0, 2) datap(ii, jj) = getushortfrombyte(buff0) Next jj fs.Read(buff0, 0, 1) dataxy(ii, 0) = buff0(0) fs.Read(buff0, 0, 1) dataxy(ii, 1) = buff0(0) fs.Read(buff0, 0, 1) datachar(ii) = buff0(0) Next ii datanum = allnum fs.Close() End If '/ <summary> '/ 验证码图片 '/ </summary> Dim bp As New System.Drawing.Bitmap(49, 20) ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected '/ <summary> '/ 特征库的长度 '/ </summary> Dim datanum As Integer = 0 ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected '/ <summary> '/ 特征库数据 '/ </summary> Dim datap(100000, 20) As System.UInt16 'ToDo: Unsigned Integers not supported ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected '/ <summary> '/ 长度与高度 '/ </summary> Dim dataxy(100000, 2) As Byte ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected '/ <summary> '/ 对应的字符 '/ </summary> Dim datachar(100000) As Byte ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '--------^--- expression expected '/ <summary> '/ 等待处理的数据 '/ </summary> Dim datapic(20) As System.UInt16 'ToDo: Unsigned Integers not supported ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected '/ <summary> '/ 有效长度 '/ </summary> Dim xlpic As Byte = 0 ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected '/ <summary> '/ 有效宽度 '/ </summary> Dim ylpic As Byte = 0 ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected '/ <summary> '/ 检索特征库中存在的记录 '/ </summary> Dim getchar As String ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '----------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '-----------------------^--- expression expected If (True) Then ' 'ToDo: Error processing original source shown below ' ' '-^--- Syntax error: ';' expected '如果查找不到,就返回空串 Dim jieguo As String = "" Dim ii As Integer For ii = 0 To datanum - 1 '统计一共有多少行的像素有差异,如果在4行以内就认为是存在该记录 '这种方法比较原始,但比较适合多线程时的运行,因为程序只进行简单的逻辑比较 '如果能够收集更多的特征库,识别率可以达到80%以上 '(此时可能需要将特征库的容量提高到15W个或以上) '当然也可以改进品配算法(如使用关键点品配),以用较少的特征库达到较高的识别率,但 '那样有比较大的机会造成识别错误并且多线程时占用较多CPU时间。 Dim notsamenum As Integer = 0 If dataxy(ii, 0) <> xlpic Or dataxy(ii, 1) <> ylpic Then GoTo ContinueFor1 End If Dim jj As Integer For jj = 0 To 19 If datap(ii, jj) <> datapic(jj) Then notsamenum += 1 End If ContinueFor1: Next jj If notsamenum < 4 Then Dim cj As Char = CChar(datachar(ii)) Return cj.ToString() End If ContinueFor1: Next ii Return jieguo End If '/ <summary> '/ 检查特征库中是否已经存在相关记录 '/ </summary> Dim ischardatain As Boolean ' 'ToDo: Error processing original source shown below ' ' '------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '-------------------^--- expression expected If (True) Then ' 'ToDo: Error processing original source shown below ' ' '-^--- Syntax error: ';' expected Dim jieguo As Boolean = False Dim ii As Integer For ii = 0 To datanum - 1 '统计一共有多少行的像素有差异,如果在4行以内就认为是存在该记录 '这种方法比较原始,但比较适合多线程时的运行,因为程序只进行简单的逻辑比较 '如果能够收集更多的特征库,识别率可以达到80%以上 '(此时可能需要将特征库的容量提高到15W个或以上) '当然也可以改进品配算法(如使用关键点品配),以用较少的特征库达到较高的识别率,但 '那样有比较大的机会造成识别错误并且多线程时占用较多CPU时间。 Dim notsamenum As Integer = 0 If System.Math.Abs((dataxy(ii, 0) - xlpic)) > 1 Or System.Math.Abs((dataxy(ii, 1) - ylpic)) > 1 Then GoTo ContinueFor1 End If Dim jj As Integer For jj = 0 To 19 If datap(ii, jj) <> datapic(jj) Then notsamenum += 1 End If ContinueFor1: Next jj If notsamenum < 4 Then Dim asdasd As String = CChar(datachar(ii)).ToString() Return True End If ContinueFor1: Next ii Return jieguo End If '/ <summary> '/ 添加到特征库中,并暂时将对应的字符置为空格以待人工识别 '/ </summary> Dim adddatawithnullchar As ' 'ToDo: Error processing original source shown below ' ' '-^--- GenCode(token): unexpected token type ' 'ToDo: Error processing original source shown below ' ' '-------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '--------------------------^--- expression expected If (True) Then ' 'ToDo: Error processing original source shown below ' ' '-^--- Syntax error: ';' expected If Me.ischardatain() Then Return End If Dim ii As Integer For ii = 0 To 19 datap(datanum, ii) = Me.datapic(ii) Next ii '暂时将对应的字符置为空格以待人工识别 datachar(datanum) = 32 dataxy(datanum, 0) = Me.xlpic dataxy(datanum, 1) = Me.ylpic datanum += 1 End If '/ <summary> '/ 检查验证码图片是否能分成4个部分,如果可以就检查4个字符在特征库中是否已经存在,如果不存在, '/ 就添加到特征库中,并暂时将对应的字符置为空格以待人工识别 '/ </summary> Dim writetodata As ' 'ToDo: Error processing original source shown below ' ' '--------^--- GenCode(token): unexpected token type ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '------------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '-------------------------^--- expression expected If (True) Then ' 'ToDo: Error processing original source shown below ' ' '-^--- Syntax error: ';' expected Dim picpixel(49, 20) As Boolean Dim ii As Integer For ii = 0 To 48 Dim jj As Integer For jj = 0 To 19 If bp.GetPixel(ii, jj).GetBrightness() < 0.999 Then picpixel(ii, jj) = True End If Next jj Next ii Dim index(8) As Integer Dim indexnum As Integer = 0 Dim black As Boolean = False Dim ii As Integer For ii = 0 To 48 Dim haveblack As Boolean = False Dim jj As Integer For jj = 0 To 19 If picpixel(ii, jj) Then haveblack = True Exit For End If Next jj If haveblack And black = False Then index(indexnum) = ii indexnum += 1 black = True End If If Not haveblack And black Then index(indexnum) = ii indexnum += 1 black = False End If Next ii If indexnum < 7 Then Return End If If indexnum = 7 Then index(7) = 49 End If '**** Dim ii As Integer For ii = 0 To 3 Dim x1 As Integer = index((ii * 2)) Dim x2 As Integer = index((ii * 2 + 1)) Dim y1 As Integer = 0 Dim y2 As Integer = 19 Dim mb As Boolean = False Dim jj As Integer For jj = 0 To 19 Dim kk As Integer For kk = x1 To x2 - 1 If picpixel(kk, jj) Then mb = True Exit For End If Next kk If mb Then y1 = jj Exit For End If Next jj mb = False Dim jj As Integer For jj = 19 To 0 Step -1 Dim kk As Integer For kk = x1 To x2 - 1 If picpixel(kk, jj) Then mb = True Exit For End If Next kk If mb Then y2 = jj Exit For End If Next jj '**以上是获取有效区域的范围 Dim jj As Integer For jj = 0 To 19 Me.datapic(jj) = 0 Me.datapic(jj) = 0 Next jj Me.xlpic = CByte(x2 - x1) '如果字符宽度超过16个像素就不予处理 If xlpic > 16 Then GoTo ContinueFor1 End If Me.ylpic = CByte(y2 - y1 + 1) Dim ys As Integer = - 1 Dim addin() As System.UInt16 = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768} 'ToDo: Unsigned Integers not supported Dim jj As Integer For jj = y1 To y2 ys += 1 Dim xs As Integer = - 1 Dim kk As Integer For kk = x1 To x2 - 1 xs += 1 If picpixel(kk, jj) Then Me.datapic(ys) = CType(Me.datapic(ys) + addin(xs), System.UInt16) 'ToDo: Unsigned Integers not supported End If ContinueFor1: Next kk ContinueFor1: Next jj Me.adddatawithnullchar() ContinueFor1: Next ii End If '**** '/ <summary> '/ 识别图片 '/ </summary> '/ <returns>返回识别结果(如果返回的字符串长度小于4就说明识别失败)</returns> Dim ocrpic As String ' 'ToDo: Error processing original source shown below ' ' '-^--- expression expected ' 'ToDo: Error processing original source shown below ' ' '---------------------^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below ' ' '----------------------^--- expression expected If (True) Then ' 'ToDo: Error processing original source shown below ' ' '-^--- Syntax error: ';' expected ' 'ToDo: Error processing original source shown below 'System.Char[] '^--- Syntax error: '}' expected Dim jieguo As String = "" Dim picpixel(49, 20) As Boolean Dim ii As Integer For ii = 0 To 48 Dim jj As Integer For jj = 0 To 19 If bp.GetPixel(ii, jj).GetBrightness() < 0.999 Then picpixel(ii, jj) = True End If Next jj Next ii Dim index(8) As Integer Dim indexnum As Integer = 0 Dim black As Boolean = False Dim ii As Integer For ii = 0 To 48 Dim haveblack As Boolean = False Dim jj As Integer For jj = 0 To 19 If picpixel(ii, jj) Then haveblack = True Exit For End If Next jj If haveblack And black = False Then index(indexnum) = ii indexnum += 1 black = True End If If Not haveblack And black Then index(indexnum) = ii indexnum += 1 black = False End If Next ii If indexnum < 7 Then Return jieguo End If If indexnum = 7 Then index(7) = 49 End If '**** Dim ii As Integer For ii = 0 To 3 Dim x1 As Integer = index((ii * 2)) Dim x2 As Integer = index((ii * 2 + 1)) Dim y1 As Integer = 0 Dim y2 As Integer = 19 Dim mb As Boolean = False Dim jj As Integer For jj = 0 To 19 Dim kk As Integer For kk = x1 To x2 - 1 If picpixel(kk, jj) Then mb = True Exit For End If Next kk If mb Then y1 = jj Exit For End If Next jj mb = False Dim jj As Integer For jj = 19 To 0 Step -1 Dim kk As Integer For kk = x1 To x2 - 1 If picpixel(kk, jj) Then mb = True Exit For End If Next kk If mb Then y2 = jj Exit For End If Next jj '**以上是获取有效区域的范围 Dim jj As Integer For jj = 0 To 19 Me.datapic(jj) = 0 Me.datapic(jj) = 0 Next jj Me.xlpic = CByte(x2 - x1) '如果字符宽度超过16个像素就不予处理 If xlpic > 16 Then GoTo ContinueFor1 End If Me.ylpic = CByte(y2 - y1 + 1) Dim ys As Integer = - 1 Dim addin() As System.UInt16 = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768} 'ToDo: Unsigned Integers not supported Dim jj As Integer For jj = y1 To y2 ys += 1 Dim xs As Integer = - 1 Dim kk As Integer For kk = x1 To x2 - 1 xs += 1 If picpixel(kk, jj) Then Me.datapic(ys) = CType(Me.datapic(ys) + addin(xs), System.UInt16) 'ToDo: Unsigned Integers not supported End If ContinueFor1: Next kk ContinueFor1: Next jj jieguo = jieguo + Me.getchar() ContinueFor1: Next ii Return jieguo End If End Sub 'New End Class 'yzm
- QQ验证码识别源代码(DOT NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码(C#/NET1.1)
- QQ验证码识别源代码
- qq验证码识别
- 验证码识别参考,qq验证码识别的一个源代码,现在已不可用,但是可以作为参考
- qq验证码识别系统
- QQ的验证码文字识别
- 验证码识别(1)
- .net1.1下邮件发送(带验证)
- Delphi QQ网页登陆验证码获取显示(非识别)
- QQ验证码识别(版本较旧,思路才是王道)
- QQ验证码识别代码,现在已经不可用
- char *转换为WCHAR[]
- C#常用日期格式处理转换
- python,mysql,MySQLDb支持中文(utf-8编码)
- WinCE EBOOT中的BootPart分析 基于WinCE6.0
- 字符串和指针
- QQ验证码识别源代码(DOT NET1.1)
- Android 语音识别学习小记--暑期大学生博客分享大赛 - 2011 Android 成长篇
- 关于通过php获取mysql表里的字段名的方法的整理
- design的根本原因
- 802.1x认证的具体配置过程
- gcc对C语言扩展
- Flex实现页面跳转的功能可用性分析
- Linux下另类内存缓冲池设计(CBufferPool)
- asmlinkage