Authentication code Identification of academic Department of Jimei University (I.)

Source: Internet
Author: User

"Original, reproduced please mark Sen Dog"

Jimei University Verification Code of 2 kinds, one is the student login with the verification code, one is the administrator backstage verification code. Such as:

(Student sign-in verification code)

Http://www.cnblogs.com/sendog/p/5568618.html

(Administrator login Verification code)

For the first type of verification code, because I mentioned in the reply how to parse the code and then poor to the academic office to crack, today has been replaced by a new style verification code, the second kind has not changed, it is estimated that soon will be changed. (Blame me)

This article will identify 2 types of verification codes in 2 different ways.

First of all

1. Remove light-colored noise

     Public Static voidSysout (bufferedimage img)throwsioexception{intHeight =img.getheight (); intwidth =img.getwidth ();  for(intx = 0; x < width; ++x) { for(inty = 0; Y < height; ++y) {intcolor =GetC (Img.getrgb (x, y)); if(color>300) {Img.setrgb (x, Y, Color.WHITE.getRGB ()); }                //System.out.println (x+ ":" +y+ ":" +color);}} imageio.write (IMG,"GIF",NewFile ("c:/users/mr.wu/desktop/Verification Code 2/ss1.gif")); }

This is mainly the control of this color>300 300 valve value. By printing a one-point contrast color, you can find that the color value of the tint is greater than 300

     Public Static int GetC (int  colorint) {        new  Color (colorint);         return (color.getred () + color.getgreen () + color.getblue ());    }

After this step the verification code after processing such as:

Only the dark color of the noise is left.

2. Deep-color noise we can remove it by using its top and bottom left and right noise points to be white. Directly on the code:

     Public Static voidSurround (bufferedimage img)throwsioexception{intHeight =img.getheight (); intwidth =img.getwidth ();  for(intx = 1; x < width-1; ++x) { for(inty = 1; Y < height-1; ++y) {ints = Img.getrgb (x, y-1); intR = Img.getrgb (x, y+1); intz = Img.getrgb (x-1, y+1); intL = Img.getrgb (x+1, y+1); intWhite =Color.WHITE.getRGB (); if(S==white && r==white && z==white && l==White )                {Img.setrgb (x, Y, Color.WHITE.getRGB ()); }}} Imageio.write (IMG,"GIF",NewFile ("c:/users/mr.wu/desktop/Verification Code 2/ss2.gif")); }

The verification code after this step is as follows:

3. Then we will simply deal with it, is to cut off the external image of the inner margin, only the main verification code.

     Public Static void throws ioexception{        = img.getsubimage (7, 4, +);         New File ("c:/users/mr.wu/desktop/Verification Code 2/ss3.gif");    }

Processing results:

4. Two value processing

     Public Static voidBlack (bufferedimage img)throwsioexception{intHeight =img.getheight (); intwidth =img.getwidth (); intWhite =Color.WHITE.getRGB ();  for(intx = 0; x < width; ++x) { for(inty = 0; Y < height; ++y) {if(Img.getrgb (x, y)! =White )                {Img.setrgb (x, Y, Color.black.getRGB ()); }}} Imageio.write (IMG,"GIF",NewFile ("c:/users/mr.wu/desktop//Verification Code 2/ss4.gif")); }

Here, the binary value as long as the other than the white color all set to black on the line, the result is as follows

=================================

After processing to this step need to cut the verification code, collect 0~9 characters, and then you can let the verification code one by one character and the collected 0~9 characters, the highest similarity is the corresponding value

5. Collect Verification Code characters

    //Split Picture     Public Static voidsplitimage (String picfile)throwsException {bufferedimage img= Imageio.read (NewFile (picfile)); BufferedImage IMG1= img.getsubimage (0, 0, 7, 12); BufferedImage Img2= Img.getsubimage (8, 0, 7, 12); BufferedImage IMG3= Img.getsubimage (18, 0, 7, 12); BufferedImage IMG4= Img.getsubimage (26, 0, 7, 12); Imageio.write (IMG1,"GIF",NewFile ("c:/users/mr.wu/desktop/Verification Code 2/img/1.gif")); Imageio.write (Img2,"GIF",NewFile ("c:/users/mr.wu/desktop/Verification Code 2/img/2.gif")); Imageio.write (IMG3,"GIF",NewFile ("c:/users/mr.wu/desktop/Verification Code 2/img/3.gif")); Imageio.write (IMG4,"GIF",NewFile ("c:/users/mr.wu/desktop/Verification Code 2/img/4.gif")); }  

6. Take the verification code of the 4th step to compare with the verification code collected in step 5th

     Public Static voidMain (string[] args)throwsException {String picfile= "c:/users/mr.wu/desktop/Verification Code 2/ss4.gif"; Map<bufferedimage, string> map =Loadtraindata (); List<BufferedImage> listimg =splitimage (Picfile); String result= "";  for(BufferedImage bi:listimg) {result+=GETSINGLECHAROCR (bi, map);    } System.out.println (Result); }             Public StaticList<bufferedimage>splitimage (String picfile)throwsException {bufferedimage img= Imageio.read (NewFile (picfile)); List<BufferedImage> Subimgs =NewArraylist<bufferedimage>(); Subimgs.add (Img.getsubimage (0, 0, 7, 12)); Subimgs.add (Img.getsubimage (8, 0, 7, 12)); Subimgs.add (Img.getsubimage (18, 0, 7, 12)); Subimgs.add (Img.getsubimage (26, 0, 7, 12)); returnSubimgs; }               Public StaticMap<bufferedimage, string> Loadtraindata ()throwsException {Map<bufferedimage, string> map =NewHashmap<bufferedimage, string>(); File dir=NewFile ("c:/users/mr.wu/desktop/Verification Code 2/IMG/1"); file[] Files=Dir.listfiles ();  for(file file:files) {map.put (Imageio.read (file), File.getname (). CharAt (0) + ""); }        returnmap; }             Public StaticString GETSINGLECHAROCR (bufferedimage img, Map<bufferedimage, string>map) {String result= ""; intwidth =img.getwidth (); intHeight =img.getheight (); intMin = width *height;  for(BufferedImage bi:map.keySet ()) {intCount = 0; Label1: for(intx = 0; x < width; ++x) { for(inty = 0; Y < height; ++y) {if(Iswhite (Img.getrgb (x, y))! =Iswhite (Bi.getrgb (x, y))) {Count++;//of different                        if(Count >=min) BreakLabel1; }                }            }            if(Count <min) {min=count; Result=map.get (BI);        }} System.out.println (Result); returnresult; }         Public Static intIswhite (intcolorint) {Color Color=NewColor (Colorint); if(color.getred () + color.getgreen () + color.getblue () > 100) {//Black for 0 white 765            return1; }        return0; }

Output Result:

Authentication code Identification of academic Department of Jimei University (I.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.