日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java验证码识别--2

發布時間:2025/3/13 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java验证码识别--2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

(本文僅用于學習研究圖像匹配識別原理,不得用于其他用途。)

換一個字體固定,大小固定,位置不固定的驗證碼

?

還是四步。

1。圖像預處理

???? 這驗證碼還是很厚道的,都沒有任何干擾。不用處理

2。分割

???? 先縱向掃描,很容易分成四部分

???

???? 再對每一部分橫向掃描

???? ???

3。訓練就容易了

???? 把分割的結果對應存成5.jpg,9.jpg,3.jpg,a.jpg 就可以了

????

4。識別

???? 因為固定大小,識別跟 驗證碼識別--1 里面一樣,像素比較就可以了。

識別結果如下,識別率100%:

?

源碼:

?public class ImagePreProcess2 { private static Map<BufferedImage, String> trainMap = null; private static int index = 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 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)); return img; } public static BufferedImage removeBlank(BufferedImage img) throws Exception { int width = img.getWidth(); int height = img.getHeight(); int start = 0; int end = 0; Label1: for (int y = 0; y < height; ++y) { int count = 0; for (int x = 0; x < width; ++x) { if (isWhite(img.getRGB(x, y)) == 1) { count++; } if (count >= 1) { start = y; break Label1; } } } Label2: for (int y = height - 1; y >= 0; --y) { int count = 0; for (int x = 0; x < width; ++x) { if (isWhite(img.getRGB(x, y)) == 1) { count++; } if (count >= 1) { end = y; break Label2; } } } return img.getSubimage(0, start, width, end - start + 1); } public static List<BufferedImage> splitImage(BufferedImage img) throws Exception { List<BufferedImage> subImgs = new ArrayList<BufferedImage>(); int width = img.getWidth(); int height = img.getHeight(); List<Integer> weightlist = new ArrayList<Integer>(); for (int x = 0; x < width; ++x) { int count = 0; for (int y = 0; y < height; ++y) { if (isWhite(img.getRGB(x, y)) == 1) { count++; } } weightlist.add(count); } for (int i = 0; i < weightlist.size();) { int length = 0; while (weightlist.get(i++) > 1) { length++; } if (length > 12) { subImgs.add(removeBlank(img.getSubimage(i - length - 1, 0, length / 2, height))); subImgs.add(removeBlank(img.getSubimage(i - length / 2 - 1, 0, length / 2, height))); } else if (length > 3) { subImgs.add(removeBlank(img.getSubimage(i - length - 1, 0, length, height))); } } return subImgs; } public static Map<BufferedImage, String> loadTrainData() throws Exception { if (trainMap == null) { Map<BufferedImage, String> map = new HashMap<BufferedImage, String>(); File dir = new File("train2"); File[] files = dir.listFiles(); for (File file : files) { map.put(ImageIO.read(file), file.getName().charAt(0) + ""); } trainMap = map; } return trainMap; } 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; int widthmin = width < bi.getWidth() ? width : bi.getWidth(); int heightmin = height < bi.getHeight() ? height : bi.getHeight(); Label1: for (int x = 0; x < widthmin; ++x) { for (int y = 0; y < heightmin; ++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("result2//" + result + ".jpg")); return result; } public static void downloadImage() { HttpClient httpClient = new HttpClient(); GetMethod getMethod = null; for (int i = 0; i < 30; i++) { getMethod = new GetMethod("http://www.pkland.net/img.php?key=" + (2000 + i)); try { // 執行getMethod int statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + getMethod.getStatusLine()); } // 讀取內容 String picName = "img2//" + i + ".jpg"; InputStream inputStream = getMethod.getResponseBodyAsStream(); OutputStream outStream = new FileOutputStream(picName); IOUtils.copy(inputStream, outStream); outStream.close(); System.out.println(i + "OK!"); } catch (Exception e) { e.printStackTrace(); } finally { // 釋放連接 getMethod.releaseConnection(); } } } public static void trainData() throws Exception { File dir = new File("temp"); File[] files = dir.listFiles(); for (File file : files) { BufferedImage img = removeBackgroud("temp//" + file.getName()); List<BufferedImage> listImg = splitImage(img); if (listImg.size() == 4) { for (int j = 0; j < listImg.size(); ++j) { ImageIO.write(listImg.get(j), "JPG", new File("train2//" + file.getName().charAt(j) + "-" + (index++) + ".jpg")); } } } } /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // downloadImage(); for (int i = 0; i < 30; ++i) { String text = getAllOcr("img2//" + i + ".jpg"); System.out.println(i + ".jpg = " + text); } } }

轉載于:https://www.cnblogs.com/marryZhan/archive/2010/08/08/2213944.html

總結

以上是生活随笔為你收集整理的java验证码识别--2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩欧美一区二区一幕 | 美女破处视频 | 在线观看9.1 | 亚洲一区天堂 | 久久久久久久久久久久国产精品 | 女同av在线| 久久国产免费 | 波多野结衣在线观看视频 | 亚洲视频一区二区三区在线观看 | 国产精品剧情 | 青青草成人免费在线视频 | 亚洲午夜在线观看 | 三级在线免费 | 久久这里只有精品99 | 特大巨交吊性xxxx | 丁香激情婷婷 | 亚洲国产精品999 | 亚洲清色| 久久77777| 欧美1区2区 | 国产a视频精品免费观看 | 亚洲天堂99 | 久久精品视频一区二区 | 国产日韩一区二区在线观看 | 手机在线免费视频 | 不卡影院一区二区 | 午夜tv影院 | 国产精品制服丝袜 | 小情侣高清国产在线播放 | 精品国产一区二区三区在线 | 亚洲毛片a | 久久久999久久久 | 干干干日日日 | 欧美精品一二三区 | 91视频国产精品 | 91久久电影 | 美女在线观看视频 | av 日韩 人妻 黑人 综合 无码 | 亚洲无吗在线观看 | 久久婷婷伊人 | 婷婷av一区二区三区 | 久草福利网 | 天天操操操 | 欧美麻豆| 国产三级国产精品国产国在线观看 | 久久久久国产精品区片区无码 | 男女一进一出视频 | 黑人操少妇 | 超碰人体 | 摸丰满大乳奶水www免费 | 三级免费看 | 少妇高潮一区二区三区99 | 成人av综合 | av之家在线| 国产超碰av| 一级做a爱片久久 | 人妻无码久久一区二区三区免费 | 波多野结衣中文字幕一区二区 | 日本黄色录象 | 欧美成人一区二免费视频软件 | 91精品视频网 | 欧美国产日韩在线观看成人 | 一区二区三区不卡视频 | 北条麻妃av在线 | 狠狠五月婷婷 | bl动漫在线观看 | 亚洲欧洲日本精品 | 亚欧三级 | 成年人av在线 | αv在线 | 性生活三级视频 | 日韩第一视频 | 亚洲色视频| 香蕉视频色版 | 亚洲精品中文无码AV在线播放 | 久久天堂视频 | 欧美毛片基地 | xxx一区二区| 一级裸体片 | 毛片在线免费观看网站 | 呦女精品 | www.日韩欧美 | 香蕉国产精品视频 | 国产做爰xxxⅹ久久久精华液 | 亚洲中文字幕无码一区二区三区 | 在线免费视频观看 | 久99热| 久久久久99精品成人片 | 91精品久久久久久久 | 美日韩一区二区三区 | 半推半就一ⅹ99av | 欧美激情久久久久 | 国产精品色婷婷 | 日韩视频精品在线 | av色网站 | 国内精品视频在线观看 | 亚洲av无码一区二区三区人妖 | 国产a免费 | 久久久二区|