- ·上一篇文章:Excel2010手机联系人导入Gmail的方法
- ·下一篇文章:Excel2010单元格打印显示不完整怎么办?
高手支招:12306验证码识别知多少
昨日,对验证码进行了升级,遭到不少用户的调侃为“干扰线”,而对于12306验证码,大家又有多少常识。 验证码验证码代码一: package org.image.test.one; import java.awt.Image; import java.awt.Toolkit; import java.awt.color.ColorSpace; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.awt.image.ColorModel; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import java.awt.image.MemoryImageSource; import java.awt.image.PixelGrabber; import java.awt.image.RescaleOp; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import javax.imageio.ImageIO; public class MyImgFilter { BufferedImage image; private int iw, ih; private int[] pixels; public MyImgFilter(BufferedImage image) { this.image = image; iw = image.getWidth(); ih = image.getHeight(); pixels = new int[iw * ih]; } /** 图像二值化 */ public BufferedImage changeGrey() { PixelGrabber pg = new PixelGrabber(image.getSource(), 0, 0, iw, ih, pixels, 0, iw); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } // 设定二值化的域值,默认值为100 int grey = 100; // 对图像进行二值化处理,Alpha值保持不变 ColorModel cm = ColorModel.getRGBdefault(); for (int i = 0; i < iw * ih; i++) { int red, green, blue; int alpha = cm.getAlpha(pixels[i]); if (cm.getRed(pixels[i]) > grey) { red = 255; } else { red = 0; } if (cm.getGreen(pixels[i]) > grey) { green = 255; } else { green = 0; } if (cm.getBlue(pixels[i]) > grey) { blue = 255; } else { blue = 0; } pixels[i] = alpha << 24 | red << 16 | green << 8 | blue; // 通过移位重新构成某一点像素的RGB值 }
高手支招:12306验证码识别知多少