参考:
http://blog.csdn.net/lanphaday/archive/2007/10/28/1852726.aspx
http://www.zhuaxia.com/item/852269537
java
000 000 0 0 00 0 0 0 0
0 000 00 0 0 0 0 0
00 00 0 0 00 0 00 0 00 0
0000 0 0 0 0 0 0 00 0 0
00 0 0 0 00 0
00 0 00 0 0 00 0
0 0 0 0 0 0 00 0
00 00 0 0 0 0 0 00 0
0 0 0 00 0 0 0 0
0 00 0 0 0 00
0 0 00 0 0 00
00 0 0 00 0 0 0 0
00 0 0 0 00 0 0 0 0 0
0 0 00 0 0 00 0000
python
[ 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 ]
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
[0, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 0, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
[ 1 , 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
[ 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 ]
http://blog.csdn.net/lanphaday/archive/2007/10/28/1852726.aspx
http://www.zhuaxia.com/item/852269537
java
package
Main;
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
public class Test {
public static void main(String[] args) throws Exception {
BufferedImage img = ImageIO.read( new URL( " file:/C:/src/python/gve/22.jpeg " ));
int imgWith = img.getWidth();
int imgHeight = img.getHeight();
int bgint = img.getRGB( 0 , 0 );
for ( int y = 0 ; y < imgHeight; y ++ ) {
System.out.println();
for ( int x = 0 ; x < imgWith; x ++ ) {
System.out.print(getBit(img, x, y,bgint));
}
}
}
private static char getBit(BufferedImage img, int x, int y, int bgint) {
int intCurtColor;
intCurtColor = img.getRGB(x, y);
return (intCurtColor == bgint) ? ' 0 ' : ' ' ;
}
}
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
public class Test {
public static void main(String[] args) throws Exception {
BufferedImage img = ImageIO.read( new URL( " file:/C:/src/python/gve/22.jpeg " ));
int imgWith = img.getWidth();
int imgHeight = img.getHeight();
int bgint = img.getRGB( 0 , 0 );
for ( int y = 0 ; y < imgHeight; y ++ ) {
System.out.println();
for ( int x = 0 ; x < imgWith; x ++ ) {
System.out.print(getBit(img, x, y,bgint));
}
}
}
private static char getBit(BufferedImage img, int x, int y, int bgint) {
int intCurtColor;
intCurtColor = img.getRGB(x, y);
return (intCurtColor == bgint) ? ' 0 ' : ' ' ;
}
}
000 000 0 0 00 0 0 0 0
0 000 00 0 0 0 0 0
00 00 0 0 00 0 00 0 00 0
0000 0 0 0 0 0 0 00 0 0
00 0 0 0 00 0
00 0 00 0 0 00 0
0 0 0 0 0 0 00 0
00 00 0 0 0 0 0 00 0
0 0 0 00 0 0 0 0
0 00 0 0 0 00
0 0 00 0 0 00
00 0 0 00 0 0 0 0
00 0 0 0 00 0 0 0 0 0
0 0 00 0 0 00 0000
python
#
encoding=utf-8
import Image,ImageEnhance,ImageFilter
import sys
image_name = " ./22.jpeg "
#去处 干扰点
im = Image.open(image_name)
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance( 2 )
im = im.convert( ' 1 ' )
# im.show() #测试查看
s = 12 # 启始 切割点 x
t = 2 # 启始 切割点 y
w = 10 # 切割 宽 +y
h = 15 # 切割 长 +x
im_new = []
for i in range( 4 ): # 验证码切割
im1 = im.crop((s + w * i + i * 2 ,t,s + w * (i + 1 ) + i * 2 ,h))
im_new.append(im1)
# im_new[0].show()#测试查看
xsize, ysize = im_new[0].size
gd = []
for i in range(ysize):
tmp = []
for j in range(xsize):
if ( im_new[0].getpixel((j,i)) == 255 ):
tmp.append( 1 )
else :
tmp.append(0)
gd.append(tmp)
#看效果
for i in range(ysize):
print gd[i]
比如 "0"
import Image,ImageEnhance,ImageFilter
import sys
image_name = " ./22.jpeg "
#去处 干扰点
im = Image.open(image_name)
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance( 2 )
im = im.convert( ' 1 ' )
# im.show() #测试查看
s = 12 # 启始 切割点 x
t = 2 # 启始 切割点 y
w = 10 # 切割 宽 +y
h = 15 # 切割 长 +x
im_new = []
for i in range( 4 ): # 验证码切割
im1 = im.crop((s + w * i + i * 2 ,t,s + w * (i + 1 ) + i * 2 ,h))
im_new.append(im1)
# im_new[0].show()#测试查看
xsize, ysize = im_new[0].size
gd = []
for i in range(ysize):
tmp = []
for j in range(xsize):
if ( im_new[0].getpixel((j,i)) == 255 ):
tmp.append( 1 )
else :
tmp.append(0)
gd.append(tmp)
#看效果
for i in range(ysize):
print gd[i]
[ 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 ]
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
[0, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 1, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 0, 1, 1, 1, 0, 0, 0, 1 ]
[0, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
[ 1 , 0, 0, 0, 0, 0, 0, 0, 1, 1 ]
[ 1, 1, 0, 0, 0, 0, 0, 1, 1, 1 ]
有时间 在学习下 匹配。
本文转自博客园刘凯毅的博客,原文链接:验证码识别(python),如需转载请自行联系原博主。