- 浏览: 1073057 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (453)
- Struts2 (30)
- Spring (14)
- iBATIS (6)
- Hibernate (13)
- JVM (5)
- JSON (10)
- Ajax (5)
- Flex (1)
- JavaScript (25)
- PowerDesigner (4)
- 项目管理 (7)
- 数据库 (29)
- 生活 (18)
- 软件应用 (21)
- 无线技术 (2)
- Linux (39)
- TOP开发学习 (2)
- JAVA工具小TIPS (2)
- Java通用 (52)
- XML (3)
- 软件测试 (29)
- Maven (10)
- Jquery (1)
- 正则表达式 (3)
- 应用服务器 (15)
- Android (5)
- linux 和windowx 下 tomcat 设置JVM (8)
- 应用服务器 连接池 (4)
- Linux 后台输出中文乱码 (1)
- Hadoop (28)
- python (2)
- Kafka (7)
- Storm (5)
- Elasticsearch (7)
- fddd (1)
最新评论
-
kafodaote:
Kafka分布式消息系统实战(与JavaScalaHadoop ...
分布式消息系统Kafka初步 -
小灯笼:
LoadRunner性能测试实战课程网盘地址:http://p ...
LoadRunner性能测试应用(八) -
成大大的:
Kafka分布式消息系统实 ...
分布式消息系统Kafka初步 -
hulalayaha2:
Loadrunner性能测试视频教程下载学习:http://p ...
LoadRunner性能测试应用(八) -
993042835:
搞好 谢谢
org.hibernate.exception.ConstraintViolationException: could not delete:
(本文仅用于学习研究图像匹配识别原理,不得用于其他用途。
最近看了看验证码的识别,先从最简单的做起吧(固定大小,固定位置,固定字体)
验证码识别基本分四步,图片预处理,分割,训练,识别
看一个最简单验证码
这是一个德克萨斯扑克的注册页面的验证码
1。图像的预处理
这种直接根据亮度设个阈值处理就可以了
view plaincopy to clipboardprint?
public static int isWhite(int colorInt) {
Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() > 100) {
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 = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
if (isWhite(img.getRGB(x, y)) == 1) {
img.setRGB(x, y, Color.WHITE.getRGB());
} else {
img.setRGB(x, y, Color.BLACK.getRGB());
}
}
}
return img;
}
public static int isWhite(int colorInt) {
Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() > 100) {
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 = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
if (isWhite(img.getRGB(x, y)) == 1) {
img.setRGB(x, y, Color.WHITE.getRGB());
} else {
img.setRGB(x, y, Color.BLACK.getRGB());
}
}
}
return img;
}
处理完图片效果为
图像基本分得比较清楚,图片分割也比较容易
2。分割
这个验证码居然是固定位置的,分割相当简单,直接截取相应位置就可以了
view plaincopy to clipboardprint?
public static List<BufferedImage> splitImage(BufferedImage img)
throws Exception {
List<BufferedImage> subImgs = new ArrayList<BufferedImage>();
subImgs.add(img.getSubimage(10, 6, 8, 10));
subImgs.add(img.getSubimage(19, 6, 8, 10));
subImgs.add(img.getSubimage(28, 6, 8, 10));
subImgs.add(img.getSubimage(37, 6, 8, 10));
return subImgs;
}
public static List<BufferedImage> splitImage(BufferedImage img)
throws Exception {
List<BufferedImage> subImgs = new ArrayList<BufferedImage>();
subImgs.add(img.getSubimage(10, 6, 8, 10));
subImgs.add(img.getSubimage(19, 6, 8, 10));
subImgs.add(img.getSubimage(28, 6, 8, 10));
subImgs.add(img.getSubimage(37, 6, 8, 10));
return subImgs;
}
3。训练
直接拿几张图片,包含0-9,每个数字一个样本就可以了,将文件名对应相应的数字
4。识别
因为是固定大小,固定位置,识别也很简单。
直接拿分割的图片跟这个十个图片一个像素一个像素的比,相同的点最多的就是结果。比如如果跟5.jpg最相似,那么识别的结果就是5。
下面是识别结果,很容易达到100%
完整代码(csdn连个附件都不支持):
view plaincopy to clipboardprint?
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.io.IOUtils;
public class ImagePreProcess {
public static int isWhite(int colorInt) {
Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() > 100) {
return 1;
}
return 0;
}
public static int isBlack(int colorInt) {
Color color = new Color(colorInt);
if (color.getRed() + color.getGreen() + color.getBlue() <= 100) {
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 = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
if (isWhite(img.getRGB(x, y)) == 1) {
img.setRGB(x, y, Color.WHITE.getRGB());
} else {
img.setRGB(x, y, Color.BLACK.getRGB());
}
}
}
return img;
}
public static List<BufferedImage> splitImage(BufferedImage img)
throws Exception {
List<BufferedImage> subImgs = new ArrayList<BufferedImage>();
subImgs.add(img.getSubimage(10, 6, 8, 10));
subImgs.add(img.getSubimage(19, 6, 8, 10));
subImgs.add(img.getSubimage(28, 6, 8, 10));
subImgs.add(img.getSubimage(37, 6, 8, 10));
return subImgs;
}
public static Map<BufferedImage, String> loadTrainData() throws Exception {
Map<BufferedImage, String> map = new HashMap<BufferedImage, String>();
File dir = new File("train");
File[] files = dir.listFiles();
for (File file : files) {
map.put(ImageIO.read(file), file.getName().charAt(0) + "");
}
return map;
}
public static String getSingleCharOcr(BufferedImage img,
Map<BufferedImage, String> map) {
String result = "";
int width = img.getWidth();
int height = img.getHeight();
int min = width * height;
for (BufferedImage bi : map.keySet()) {
int count = 0;
Label1: for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
if (isWhite(img.getRGB(x, y)) != isWhite(bi.getRGB(x, y))) {
count++;
if (count >= min)
break Label1;
}
}
}
if (count < min) {
min = count;
result = map.get(bi);
}
}
return result;
}
public static String getAllOcr(String file) throws Exception {
BufferedImage img = removeBackgroud(file);
List<BufferedImage> listImg = splitImage(img);
Map<BufferedImage, String> map = loadTrainData();
String result = "";
for (BufferedImage bi : listImg) {
result += getSingleCharOcr(bi, map);
}
ImageIO.write(img, "JPG", new File("result\\"+result+".jpg"));
return result;
}
public static void downloadImage() {
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(
"http://www.puke888.com/authimg.php");
for (int i = 0; i < 30; i++) {
try {
// 执行getMethod
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: "
+ getMethod.getStatusLine());
}
// 读取内容
String picName = "img\\" + i + ".jpg";
InputStream inputStream = getMethod.getResponseBodyAsStream();
OutputStream outStream = new FileOutputStream(picName);
IOUtils.copy(inputStream, outStream);
outStream.close();
System.out.println("OK!");
} catch (Exception e) {
e.printStackTrace();
} finally {
// 释放连接
getMethod.releaseConnection();
}
}
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
for (int i = 0; i < 30; ++i) {
String text = getAllOcr("img\\" + i + ".jpg");
System.out.println(i + ".jpg = " + text);
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/problc/archive/2010/08/07/5794460.aspx
个人签名
-------------------------------------
发表评论
-
java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
2013-05-10 16:10 777C:\Program Files (x86)\MyEc ... -
读取word pdf中的文字 用第三方组件 pdfbox 和 poi
2013-03-20 23:51 943读取word pdf中的文字 用第三方组件 pdfbox 和 ... -
非常好使的FileUtil 类
2013-03-09 12:45 969package com.zqk.util; imp ... -
eclipse 3.4.1 导入项目后 Target runtime Apache Tomcat v5.0 is not defi...
2012-05-29 09:27 1776下载最新版本eclipse3.4.1后,导入以前的项目,报 ... -
MyEclipse 6.5 序列号生成器
2011-06-10 09:47 1632import java.awt.event.ActionEve ... -
字节序 整形与字节数组转换
2010-12-15 13:43 2309Big Endian and Little Endian ... -
JPEG文件数据结构以及将位图保存为JPG的代码 转2
2010-12-02 13:31 2801三、实例分析 用系统自带的画图程序画一个32×24的红色方块 ... -
JPEG文件数据结构以及将位图保存为JPG的代码 转1
2010-12-02 13:30 3004JPEG文件数据结构以及将位图保存为JPG的代码一、简 ... -
Nginx+resin调优文档
2010-11-18 17:02 2269http://blog.liuts.com/post/204/ ... -
分析 Tomcat startup.bat 启动脚本
2010-11-03 14:53 3188分析 Tomcat startup.bat 启 ... -
Tomcat配置优化 转
2010-11-03 14:51 10351.精简Tomcat和配置文件1.1 .删除不需要的管理应用和 ... -
URLConnection 读取字节流
2010-10-27 13:15 32292008-11-08 山寨Wget实现又惹事了 h ... -
字节到整形的转换
2010-10-27 12:47 1368public byte[] intToByte(int i) ... -
Gif 文件格式分析
2010-10-27 11:45 1018GIF文档ˉˉˉˉˉˉ 1.概述~~~~~~~~ ... -
JPG文件格式解码图片高度和宽度的分析
2010-10-27 10:34 977213. 简单说一下 JPG 文件的解码 ---------- ... -
CSS制作多种链接样式
2010-10-15 11:54 1084多种链接样式制作方法 ... -
虚拟主机上给一个网卡设置多个IP地址
2010-10-13 17:22 1832配置虚拟主机时有一种方式是在一块网卡上绑定多个IP,操作如下: ... -
linux下一个网卡配置多个IP
2010-10-13 17:21 928文本控制台下面有netconfig,还有ifconfig工具, ... -
[转载]linux中sar的详细使用
2010-10-13 17:06 856在使用UNIX操作系统的过程中,我们常常 ... -
Linux中sar命令
2010-10-13 17:05 958Linux中sar命令 sar这东 ...
相关推荐
java验证码识别示例
java 验证码识别 ocr java 验证码识别 ocr
java验证码识别 JAVA知识巩固 源码 java验证码识别 java验证码识别
java验证码识别源码,验证码生成地址自己添加,main 函数两个方法取消注释
java 验证码识别源程序 windows版本 概率90%以上
java 验证码识别 OCR。
1. 12306登录验证码识别基于深度学习; 2. 解压send.rar后在里面的bin目录下找到client.exe,并打开 3. 在client界面中点击选择图片中,选择send文件夹中Images中的图片,点击client界面的send按钮后,程序就会把...
java验证码识别,可识别验证码的小程序,源代码很详细哦
国内第一个绝对高识别率,高效率的Java 验证码识别引擎,推荐使用于自动发贴机、数据采集系统的图片验证码自动识别场合!使用方法:下载解压后,导入Eclipse或MyEclipse中,然后在c:盘下放置一张验证码图片(如:...
[验证码识别-部署]本项目基于CNN+BLSTM+CTC实现验证。此 projeccode 标识仅适用于部署模型。
图片验证码识别的测试例子,经测试中英字符识别率90%以上
例子中是一个Java识别验证码的例子,下载解压后导入工程,在E盘放入一张验证图片,然后运行Main函数即可。
在本篇文章里小编给大家分享的是关于Java 如何使用 OCR 技术识别验证码实现自动化登陆的相关知识点内容,需要的朋友们学习下。
基于 Java 的简单图形验证码识别
JAVA智能验证码识别,可训练提高识别率,带干扰线的也可以识别到,绝对可用
基于Java的简单图形验证码识别源码.zip基于Java的简单图形验证码识别源码.zip基于Java的简单图形验证码识别源码.zip基于Java的简单图形验证码识别源码.zip基于Java的简单图形验证码识别源码.zip基于Java的简单图形...
增加了细化算法。 增加了注释 界面稍微变了变
java简单图形验证码识别样例,java简单图形验证码识别样例
java项目 验证码识别