Recent research Verification Code recognition, also looked at some image recognition data, one of the font refinement to extract skeleton of the algorithm on-line without Java version of the implementation, so chose a Python implementation version of the Java code rewrite.
The Python version implements the address:
Http://www.cnblogs.com/xianglan/archive/2011/01/01/1923779.html
Because I do not understand the Python grammar, but also go directly to the view of the language of the tutorial, for this also fell into a pit. See:
Http://www.cnblogs.com/chyu/p/4335950.html
Because I am not very good at image processing here, Python is also a temporary look, so this refinement of the skeleton extraction algorithm is the direct migration of the original code, and did not do anything optimization, and so on. The code is rough.
PackageCOM.OCR.IMGOCR;ImportJava.awt.Color;ImportJava.awt.image.BufferedImage;ImportJava.io.File;Importjava.io.IOException;ImportJavax.imageio.ImageIO; Public classThin {//indexed Array Private StaticInteger[] Array = {0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1, 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1, 0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1, 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1, 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,0,0,1,1,0,0,1,1,0,1,1,1,0,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1, 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1, 0,0,1,1,0,0,1,1,1,1,0,1,1,1,0,1, 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, 1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0, 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0, 1,1,0,0,1,1,0,0,1,1,0,1,1,1,0,0, 1,1,0,0,1,1,1,0,1,1,0,0,1,0,0,0}; Public Static BooleanIswhite (intcolorint) {Color Color=NewColor (Colorint); if(color.getred () + color.getgreen () + color.getblue () > 400) { return true; } return false; } Public Staticbufferedimage Vthin (bufferedimage image,integer[] array) {inth =image.getheight (); intW =image.getwidth (); intNEXT = 1; for(inti=0;i){ for(intj=0;j<w;j++){ if(NEXT = 0) {NEXT= 1; }Else{ intM; if(0<j&&j<w-1){ if(Isblack (Image.getrgb (j-1,i)) &&isblack (Image.getrgb (j,i)) &&isblack (Image.getrgb (j+1, i))) {M=0; }Else{M=1; } }Else{M= 1; } if(Isblack (Image.getrgb (j,i)) &&m!=0){ int[] A = {0,0,0,0,0,0,0,0,0}; for(intk=0;k<3;k++){ for(intl=0;l<3;l++){ if(( -1< (i-1+k) && (i-1+k) k))) {A[k*3+L] = 1; } } } intsum = a[0]*1+a[1]*2+a[2]*4+a[3]*8+a[5]*16+a[6]*32+a[7]*64+a[8]*128; if(array[sum]==0) {Image.setrgb (J, I, Color.black.getRGB ()); }Else{Image.setrgb (J, I, Color.white.getRGB ()); } if(Array[sum] = = 1) {NEXT= 0; } } } } } returnimage; } Public Staticbufferedimage Hthin (bufferedimage image,integer[] array) {inth =image.getheight (); intW =image.getwidth (); intNEXT = 1; for(intj=0;j<w;j++){ for(inti=0;i){ if(NEXT = 0) {NEXT= 1; }Else{ intM; if(0<i&&i){ if(Isblack (Image.getrgb (j,i-1)) &&isblack (Image.getrgb (j,i)) &&isblack (Image.getrgb (j,i+1)) ) {M=0; }Else{M=1; } }Else{M= 1; } if(Isblack (Image.getrgb (j,i)) && M! = 0){ int[] A = {0,0,0,0,0,0,0,0,0}; for(intk=0;k<3;k++){ for(intl=0;l<3;l++){ if(( -1< (i-1+k) && (i-1+k) k))) {A[k*3+L] = 1; } } } intsum = a[0]*1+a[1]*2+a[2]*4+a[3]*8+a[5]*16+a[6]*32+a[7]*64+a[8]*128; if(array[sum]==0) {Image.setrgb (J, I, Color.black.getRGB ()); }Else{Image.setrgb (J, I, Color.white.getRGB ()); } if(Array[sum] = = 1) {NEXT= 0; } } } } } returnimage; } Public Staticbufferedimage Xihua (bufferedimage image,integer[] array) {intnum=10;BufferedImage Ixihua =image; for(inti=0;i<num;i++) {Vthin (Ixihua,array); Hthin (Ixihua,array); } returnIxihua; } Public StaticBufferedImage (bufferedimage image) {intW =image.getwidth (); inth =image.getheight (); BufferedImage ITwo=image; for(inti=0;i){ for(intj=0;j<w;j++){ if(Isblack (Image.getrgb (j,i))) {Itwo.setrgb (J, I, Color.BLACK.getRGB ()); }Else{Itwo.setrgb (J, I, Color.WHITE.getRGB ()); } } } returnITwo; } Public Static BooleanIsblack (intcolorint) {Color Color=NewColor (Colorint); if(color.getred () + color.getgreen () + color.getblue () <= 400) { return true; } return false; } Public Static voidMain (string[] args) {Try { //Original picture PathBufferedImage image = Imageio.read (NewFile ("image" +file.separator+ "0.jpg")); //two value ofBufferedImage ITwo =(image); Imageio.write (ITwo,"JPG",NewFile ("image" +file.separator+ "two.jpg")); //RefinementBufferedImage Ithin =Xihua (Image,array); Imageio.write (Ithin,"JPG",NewFile ("image" +file.separator+ "thin.jpg")); } Catch(IOException e) {e.printstacktrace (); } }}
Java implementation of skeleton algorithm extraction based on index refinement