java识别验证码 仅限字母数字 附带bmp图片 验证码图片位置随机变动
2022-03-23 16:21:31 846KB java识别验证码
1
java 利用orc智能识别图像字符技术,虽然说不能够百分百识别,但还算有点用。package com.ocr; import java.awt.Graphics2D; 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.MemoryImageSource; import java.awt.image.PixelGrabber; /** * * 图像过滤,增强OCR识别成功率 * */ public class ImageFilter { private BufferedImage image; private int iw, ih; private int[] pixels; public ImageFilter(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 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; } // 将数组中的象素产生一个图像 return ImageIOHelper.imageProducerToBufferedImage(new MemoryImageSource(iw, ih, pixels, 0, iw)); } /** 提升清晰度,进行锐化 */ public BufferedImage sharp() { PixelGrabber pg = new PixelGrabber(image.getSource(), 0, 0, iw, ih, pixels, 0, iw); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } // 象素的中间变量 int tempPixels[] = new int[iw * ih]; for (int i = 0; i < iw * ih; i++) { tempPixels[i] = pixels[i]; } // 对图像进行尖锐化处理,Alpha值保持不变 ColorModel cm = ColorModel.getRGBdefault(); fo
2021-09-30 16:52:00 51.08MB 识别验证码
1
java识别验证码 仅限字母数字 附带bmp图片
2021-04-03 10:57:48 846KB 识别验证码
1