QQ verification code identification source code (C # / Net1.1) Using System; Namespace QQ {/// /// yzm summary description.
/// summary> public class yzm {public yzm (public system.drawing.bitmap pic) {this.bp = pic;} /// /// The INT value is stored in 4 bytes The byte array (from the high address starting, the value of the highest address is involved in "and the calculation") /// summary> /// INT value to process < / param> /// Storage information Character array param> public static void getBytesfromint (int thevalue, byte [] thebuff) {long v1 = 0; long V2 = 0; long v3 = 0; long b1 = 0; uint b1 = (uint) 4278190080; uint b2 = (uint) 16711680; uint b3 = (uint) 65280; uint b4 = (uint) 255; v1 = thevalue & b1; v2 = thevalue & b2 ; v4 = thevalue & b3; v4 = thevalue & b4; thebuff [0] = (byte) (v1 >> 24); thebuff [1] = (byte) (v2 >> 16); thebuff [2] = (Byte ) (v3 >> 8); thebuff [3] = (byte) v4;} /// /// Put a USHORT value into a two byte array (from the high address starting, The value of the highest address is involved in "and calculations") /// summary> /// parame> //// Storage information Character array 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); Thevalue & B2); Thebuff [0] = (Byte) (V1 >> 8); Thebuff [1] = (Byte) (V2);} /// /// converts 4 bytes of byte arrays into an int value /// summary> /// character array param> /// return> 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;} /// /// converts two byte arrays into a Ushort value /// summary > /// Characters param> /// returns> public static ushort getushortfrombyte (byte [] thebuff) {Int jieguo1 = 0; jieguo1 = (THEBUFF [0 ] << 8) thebuff [1]; Ushort Jieguo = (Ushort) Jieguo1; Return Jieguo;} /// /// Write data in memory (save the feature library) /// Summary> /// Saved location 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> /// Read information from the file and saves the corresponding position in memory /// summary> /// Special library file param> public static void readfromfile s TRING 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 (bYTE [] buff0 = new byte [2]; for (int II = 0; II
Buff0 [0];} datanum = allnum; fs.close ();} /// /// verification code picture /// summary> public system.drawing.bitmap bp = new system.drawing.bitmap (49, 20); /// /// The length //// summary> public static int datanum = 0; /// /// Characteristic library data /// Summary> public static ushort [,] datap = new usort [100000, 20]; /// /// length and height /// summary> public static byte [,] dataxy = new byte [100000, 2]; /// /// Corresponding characters /// summary> public static Byte [] DataChar = new byte [100000]; /// /// Wait for processing data // / summary> public ushort [] datapic = new ushort [20]; /// /// valid length /// summary> public byte xlpic = 0; /// /// Effective Width /// Summary> Public Byte YLPIC = 0; /// /// Retrieving Records in the Database /// Summary> Public String getChar () {// If the lookup is not available , Return to the air string string jieguo = ""; for (int II = 0; II
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 ;}}}}} f (notsamenum <4) {char CJ = (char) DataChar [II]; Return Cj.toString ();}} Return Jieguo;} /// /// Check if there is a correlation record in the feature library /// summary> BOOL ISCHARDATAIN () {bool jieguo = false; for (int II = 0; II
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 ;}}} f (notsamenum <4) {string asdasd = ((char) DataChar [II] ) .Tostring (); return true;}}}}}} /// /// Add to the feature library, temporarily set the corresponding character to a space to be manually identified /// summary> Void adddatawithnullchar () {if (this.ischardata ()) {return;} for (int II = 0; II <20; II ) {datap [datanum, II] = this.dataPic [II];} // temporarily The corresponding character is set to be spaced to manually identify DataChar [datanum] = 32; Dataxy [datanum, 0] = this.xlpic; dataxy [datanum, 1] = this.ylpic; datanum ;} /// // / Check if the verification code image can be divided into 4 parts, if you can check if 4 characters already exist in the feature library, if not, // is added to the feature library, and temporarily set the corresponding character to space To be manually identified /// /// 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]; 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 ]) {Haveb lack = true; break;}} if (haveblack && black == false) {index [indexnum] = ii; indexnum ; black = true;} if (! haveblack && black) {index [indexnum] = ii; indexnum ; black = false;}} f (indexnum <7) {return;}} (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
) {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 16) {Continue;} this.ylpic = (byte) (Y2-Y1 1); int ys = -1; Ushort [] address [] {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 108, 4096, 8192, 16384, 32768}; for (int JJ = Y1; JJ <= Y2; JJ ) {ys ; int XS = -1; for (int KK = x1; kk /// identification picture /// summary> /// Return to the identification result (if the resulting string length is less than 4, the identification failed) 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 ) {b OOL Haveblack = false; for (int JJ = 0; JJ <20; JJ ) {if (Picpixel [II, JJ]) {haveblack = true; break;}} == false {index [indexnum ] = II; IndexNum ; Black = true;} if (! Haveblack&& black) {index [indexnum] = II; indexnum ; black = false;}} f (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 =