集美大学教务处验证码识别(一)
【原创,转载请标明作者:森狗】
集美大学验证码分2种,一种是学生登入用的验证码,一种是管理员后台的验证码。如下图:
(学生登入验证码)
http://www.cnblogs.com/sendog/p/5568618.html
(管理员登入验证码)
对于第一种验证码,因为我在答辩时候提到如何解析验证码然后穷举教务处破解后,今天已经被换成新的款式验证码了,第二种暂时还没换,估计不久后也会换了。(怪我)
本文将用2中不同的方法识别2种验证码。
一、先讲第一种
1.去除淡色噪点
public static void sysout(BufferedImage img) throws IOException{int height = img.getHeight();int width = img.getWidth();for (int x = 0; x < width; ++x) {for (int y = 0; y < height; ++y) {int color = getC(img.getRGB(x, y));if(color>300){img.setRGB(x, y, Color.WHITE.getRGB());}//System.out.println(x+":"+y+":"+color); }}ImageIO.write(img, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/ss1.gif"));}
主要是这个color>300 300这个阀值的控制。通过打印一个个位点对比颜色,就可以发现淡色的color值是大于300的
public static int getC(int colorInt){Color color = new Color(colorInt);return (color.getRed() + color.getGreen() + color.getBlue());}
经过这一步处理后的验证码如下图:
就只剩下深颜色的噪点了。
2.深颜色的噪点我们可以通过它的上下左右噪点是白色的来去除。直接上代码:
public static void surround(BufferedImage img)throws IOException{int height = img.getHeight();int width = img.getWidth();for (int x = 1; x < width-1; ++x) {for (int y = 1; y < height-1; ++y) {int s = img.getRGB(x, y-1);int r = img.getRGB(x, y+1);int z = img.getRGB(x-1, y+1);int l = img.getRGB(x+1, y+1);int white = Color.WHITE.getRGB();if(s==white && r==white && z==white && l==white){img.setRGB(x, y, Color.WHITE.getRGB());}}}ImageIO.write(img, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/ss2.gif"));}
这步处理后的验证码如下:
3.之后我们再简单处理一下,就是切割掉外围图片的内边距,只剩下主体验证码。
public static void splitPhoto(BufferedImage img) throws IOException{BufferedImage newImg = img.getSubimage(7, 4, 33, 12);ImageIO.write(newImg, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/ss3.gif"));}
处理结果:
4.二值化处理
public static void black(BufferedImage img) throws IOException{int height = img.getHeight();int width = img.getWidth();int white = Color.WHITE.getRGB();for (int x = 0; x < width; ++x) {for (int y = 0; y < height; ++y) {if(img.getRGB(x, y)!=white){img.setRGB(x, y, Color.black.getRGB());}}}ImageIO.write(img, "gif", new File("C:/Users/Mr.wu/Desktop//验证码2/ss4.gif")); }
这边二值化只要把除了白色的以外的颜色全部设置为黑色就行了,结果如下
=================================
处理到这步后需要对验证码进行切割,收集0~9的字符,之后可以让验证码一个个字符与收集的0~9字符对比,相似度最高的就是对应的数值
5.收集验证码字符
//分割图片public static void splitImage(String picFile) throws Exception {BufferedImage img = ImageIO.read(new File(picFile));BufferedImage img1 = img.getSubimage(0, 0, 7, 12);BufferedImage img2 = img.getSubimage(8, 0, 7, 12);BufferedImage img3 = img.getSubimage(18, 0, 7, 12);BufferedImage img4 = img.getSubimage(26, 0, 7, 12);ImageIO.write(img1, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/img/1.gif"));ImageIO.write(img2, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/img/2.gif"));ImageIO.write(img3, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/img/3.gif"));ImageIO.write(img4, "gif", new File("C:/Users/Mr.wu/Desktop/验证码2/img/4.gif"));}
6.拿第4步的验证码来和第5步收集的验证码对比
public static void main(String[] args) throws Exception {String picFile = "C:/Users/Mr.wu/Desktop/验证码2/ss4.gif";Map<BufferedImage, String> map = loadTrainData();List<BufferedImage> listImg = splitImage(picFile);String result = "";for (BufferedImage bi : listImg) {result += getSingleCharOcr(bi, map);}System.out.println(result);}public static List<BufferedImage> splitImage(String picFile) throws Exception {BufferedImage img = ImageIO.read(new File(picFile));List<BufferedImage> subImgs = new ArrayList<BufferedImage>(); subImgs.add(img.getSubimage(0, 0, 7, 12)); subImgs.add(img.getSubimage(8, 0, 7, 12)); subImgs.add(img.getSubimage(18, 0, 7, 12)); subImgs.add(img.getSubimage(26, 0, 7, 12)); return subImgs; } public static Map<BufferedImage, String> loadTrainData() throws Exception {Map<BufferedImage, String> map = new HashMap<BufferedImage, String>();File dir = new File("C:/Users/Mr.wu/Desktop/验证码2/img/1");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);}}System.out.println(result);return result;}public static int isWhite(int colorInt) {Color color = new Color(colorInt);if (color.getRed() + color.getGreen() + color.getBlue() > 100) {//黑色为0 白色765return 1;}return 0;}
输出结果:
转载于:https://www.cnblogs.com/sendog/p/5568435.html
集美大学教务处验证码识别(一)相关推荐
- 东大教务处验证码破解
东北大学教务处编的很烂,一点鼠标键,它就着急拉慌说:"不当的拷贝会损坏您的系统".东大教务处的验证码是最简单的那一种,形同虚设,很易破解. 一.东大教务处验证码特点概述 先上几张图 ...
- MATLAB简易验证码识别程序介绍
本推文主要识别的验证码是这种: 第一步: 二值化 所谓二值化就是把不需要的信息通通去除,比如背景,干扰线,干扰像素等等,只剩下需要识别的文字,让图片变成2进制点阵. 第二步: 文字分割 为了能识别出字 ...
- ocr智能图文识别 tess4j 图文,验证码识别
最近写爬虫采集数据,遇到网站登录需要验证码校验,想了想有两种解决办法 1,利用htmlunit,将验证码输入到swing中,并弹出一个输入框,手动输入验证码,这种实现方式,如果网站需要登录一次可以使用 ...
- 实战:CNN+BLSTM+CTC的验证码识别从训练到部署 | 技术头条
作者|_Coriander 转载自Jerry的算法和NLP(ID: gh_36eba310d433) 1.前言 本项目适用于Python3.6,GPU>=NVIDIA GTX1050Ti,原ma ...
- 基于Python的验证码识别技术
基于Python的验证码识别技术 作者:强哥 概述 前言 准备工作 识别原理 图像处理 切割图像 人工标注 训练数据 检测结果 搞笑一刻 福利一刻 推荐阅读 前言 很多网站登录都需要输入验证码,如果要 ...
- 5行Python实现验证码识别,太稳了
很久之前,分享过一次Python代码实现验证码识别的办法. 当时采用的是pillow+pytesseract,优点是免费,较为易用.但其识别精度一般,若想要更高要求的验证码识别,初学者就只能去选择使用 ...
- curlopt_ssl_verifypeer后https还是验证不过_验证码识别竞赛解决方案(97%+一等奖)
前言:这个库是为验证码识别竞赛而开发的一个基于pytorch实现的端到端的验证码识别系统.前后开发大概有2个月,其中大部分时间都在调参,后期参考kaggle大神经验,加入了一些trick,但是由于第一 ...
- 验证码识别,发票编号识别(转)
毕业设计做了一个简单的研究下验证码识别的问题,并没有深入的研究,设计图形图像的东西,水很深,神经网络,机器学习,都很难.这次只是在传统的方式下分析了一次. 今年工作之后再也没有整理过,前几天一个家伙要 ...
- 图像验证码识别(七)——字符分割
2019独角兽企业重金招聘Python工程师标准>>> 前面经过各种去除噪点.干扰线,验证码图片现在已经只有两个部分,如果pixel为白就是背景,如果pixel为黑就为字符.正如前面 ...
最新文章
- linux和windows接口中文乱码_使用jmeter进行接口自动化实例
- python opengl 入门
- wukong引擎源码分析之搜索——docid有序的数组里二分归并求交集,如果用跳表的话,在插入索引时会更快...
- 努力一下,还是可以成为技术美术(TA)的
- matlab如何进行数字信号处理,数字信号处理基础及MATLAB实现(第2版)
- flog和flag_FLAG:写作,英语和持续学习
- Android 进程间通信
- java自定义tag,tag文件与tag标记,java自定义标签
- oracle解锁用户实例,在Oracle 11G R2里启用示例帐户scott
- hdu 1203 I NEED A OFFER!
- UVa11988 Broken Keyboard (a.k.a. Beiju Text)
- CodeVs天梯白银Silver题解
- [转载] 整理总结 python 中时间日期类数据处理与类型转换(含 pandas)
- 关于基因差异化的那些事 edger Deseq2和limma的使用及一些总结
- lambda表达式_C++11的lambda表达式递归
- 标准紧固件孔、螺栓孔、自攻螺钉孔、螺纹孔、铆钉孔、腰孔、标准排水孔工艺及规范性公布
- 车载激光扫描系统检校
- Meterpreter命令详解
- 无80端口情况下使用 CertBot 申请SSL证书 并实现自动续期
- 一部手机即可轻松玩转抖音四大主流变现方式——匀思电商