纯java 验证码识别_java验证码识别--4

(本文仅用于学习研究图像匹配识别原理,不得用于其他用途。)

验证码识别如果识别率都是100%,那验证码也就没存在的必要了。

其实很多验证码能达到10%的识别率就不错了。

下面来一个稍微复杂一点的,识别率85%左右。

看验证码

0_1282997707NJ1U.gif

挑一张来看

0_128299792900tz.gif

放大看,我们会发现干扰线是纯黑色的,因此去干扰线的方法就有了

对点color[i][j],如果color[i+1][j],color[i-1][j],color[i][j+1],color[i][j-1]都是纯黑或者纯白色的,就认为color[i][j]是干扰,将color[i][j]置为白色。

处理之后

0_128300037402g0.gif

这样就简单了,分割也简单。

识别结果

0_1283000823zw3q.gif

啥也不说了,贴代码

public class ImagePreProcess4 {

private static Map trainMap = null;

private static int index = 0;

public static int isBlack(int colorInt) {

Color color = new Color(colorInt);

if (color.getRed() + color.getGreen() + color.getBlue() <= 300) {

return 1;

}

return 0;

}

public static int isWhite(int colorInt) {

Color color = new Color(colorInt);

if (color.getRed() + color.getGreen() + color.getBlue() > 300) {

return 1;

}

return 0;

}

public static int getColorBright(int colorInt) {

Color color = new Color(colorInt);

return color.getRed() + color.getGreen() + color.getBlue();

}

public static int isBlackOrWhite(int colorInt) {

if (getColorBright(colorInt) < 30 || getColorBright(colorInt) > 730) {

return 1;

}

return 0;

}

public static BufferedImage removeBackgroud(String picFile)

throws Exception {

BufferedImage img = ImageIO.read(new File(picFile));

int width = img.getWidth();

int height = img.getHeight();

for (int x = 1; x < width - 1; ++x) {

for (int y = 1; y < height - 1; ++y) {

if (getColorBright(img.getRGB(x, y)) < 100) {

if (isBlackOrWhite(img.getRGB(x - 1, y))

+ isBlackOrWhite(img.getRGB(x + 1, y))

+ isBlackOrWhite(img.getRGB(x, y - 1))

+ isBlackOrWhite(img.getRGB(x, y + 1)) == 4) {

img.setRGB(x, y, Color.WHITE.getRGB());

}

}<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值