// int blue2 = cm.getBlue(pixels[(i - 1) * iw + j]);
int blue4 = cm.getBlue(pixels[i * iw + j - 1]);
int blue5 = cm.getBlue(pixels[i * iw + j]);
int blue6 = cm.getBlue(pixels[i * iw + j + 1]);
// int blue8 = cm.getBlue(pixels[(i + 1) * iw + j]);
// 水平方向进行中值滤波
if (blue4 >= blue5) {
if (blue5 >= blue6) {
blue = blue5;
} else {
if (blue4 >= blue6) {
blue = blue6;
} else {
blue = blue4;
}
}
} else {
if (blue4 > blue6) {
blue = blue4;
} else {
if (blue5 > blue6) {
blue = blue6;
} else {
blue = blue5;
}
}
}
pixels[i * iw + j] = alpha << 24 | red << 16 | green << 8 | blue;
}
}
// 将数组中的象素产生一个图像
Image tempImg = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(iw, ih, pixels, 0, iw));
image = new BufferedImage(tempImg.getWidth(null), tempImg.getHeight(null), BufferedImage.TYPE_INT_BGR);
image.createGraphics().drawImage(tempImg, 0, 0, null);
return image;
}
public BufferedImage getGrey() {
ColorConvertOp ccp = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
return image = ccp.filter(image, null);
}
// Brighten using a linear formula that increases all color values
public BufferedImage getBrighten() {
RescaleOp rop = new RescaleOp(1.25f, 0, null);
return image = rop.filter(image, null);
}
// Blur by "convolving" the image with a matrix
public BufferedImage getBlur() {
float[] data = { .1111f, .1111f, .1111f, .1111f, .1111f, .1111f, .1111f, .1111f, .1111f, };
ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, data));
return image = cop.filter(image, null);
}
// Sharpen by using a different matrix
public BufferedImage getSharpen() {
float[] data = { 0.0f, -0.75f, 0.0f, -0.75f, 4.0f, -0.75f, 0.0f, -0.75f, 0.0f };
ConvolveOp cop = new ConvolveOp(new Kernel(3, 3, data));
return image = cop.filter(image, null);
}
// 11) Rotate the image 180 degrees about its center point
public BufferedImage getRotate() {
AffineTransformOp atop = new AffineTransformOp(AffineTransform.getRotateInstance(Math.PI, image.getWidth() / 2, image.getHeight() / 2), AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
return image = atop.filter(image, null);
}
public BufferedImage getProcessedImg() {
return image;
}
public static void main(String[] args) throws IOException {
FileInputStream fin = new FileInputStream("F:\\passCode.jpg");
BufferedImage bi = ImageIO.read(fin);
MyImgFilter flt = new MyImgFilter(bi);
flt.changeGrey();
flt.getGrey();
flt.getBrighten();
bi = flt.getProcessedImg();
//String pname = args[0].substring(0, args[0]stIndexOf("."));
File file = new File( "F:\\passCode.jpg");
ImageIO.write(bi, "jpg", file);
}
}
验证码代码二:
String path = "D:\\passCodeAction.jpg";
FileInputStream fin = new FileInputStream(path);
BufferedImage bi = ImageIO.read(fin);
MyImgFilter flt = new MyImgFilter(bi);
flt.changeGrey();
flt.getMedian();
flt.getGrey();
flt.getBrighten();
bi = flt.getProcessedImg();
12306网站升级动态验证码,闪得人心烦,对于紧张抢票的时刻,怎么能可以因为动态验证码而错失良机。以上就是巧用Tesseract-OCR来破解12306的验证码,根据以上提供的方法,大家就可以快速识别12306的验证码,比任何人都快一步。