摘要圖像識別是目前很熱門的研究領(lǐng)域,涉及的知識很廣,包括信息論、模式識別、模糊數(shù)學(xué)、圖像編碼、內(nèi)容分類等等。本文僅對使用Java實(shí)現(xiàn)了一個簡單的圖像文本二值處理,關(guān)于識別并未實(shí)現(xiàn)。
成都創(chuàng)新互聯(lián)主營安塞網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,安塞h5小程序制作搭建,安塞網(wǎng)站營銷推廣歡迎安塞等地區(qū)企業(yè)咨詢
步驟
建立文本字符模板二值矩陣
對測試字符進(jìn)行二值矩陣化處理
代碼
/*
* @(#)StdModelRepository.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package cn.edu.ynu.sei.recognition.util;import java.awt.Image;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.List;import java.util.logging.Level;import java.util.logging.Logger;import javax.imageio.ImageIO;/** * Hold character charImgs as standard model repository.
* @author 88250
* @version 1.0.0.0, Mar 20, 2008
*/
public class StdModelRepository {
/** * hold character images
*/ List charImgs = new ArrayList();
/** * default width of a character
*/ static int width = 16 /** * default height of a character
*/ static int height = 28 /** * standard character model matrix
*/ public int[][][] stdCharMatrix = new int[27][width][height];
/** * Default constructor.
*/ public StdModelRepository() {
BufferedImage lowercase = null try {
lowercase = ImageIO.read(new File("lowercase.png"));
} catch (IOException ex) {
Logger.getLogger(StdModelRepository.class.getName()).
log(Level.SEVERE, null, ex);
}
for (int i = 0 i 26 i++) {
charImgs.add(lowercase.getSubimage(i * width,
0,
width,
height));
}
for (int i = 0 i charImgs.size(); i++) {
Image image = charImgs.get(i);
int[] pixels = ImageUtils.getPixels(image,
image.getWidth(null),
image.getHeight(null));
stdCharMatrix[i] = ImageUtils.getSymbolMatrix(pixels, 0).clone();
ImageUtils.displayMatrix(stdCharMatrix[i]);
}
}
}
/*
* @(#)ImageUtils.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package cn.edu.ynu.sei.recognition.util;import java.awt.Image;import java.awt.image.PixelGrabber;import java.util.logging.Level;import java.util.logging.Logger;/** * Mainipulation of image data.
* @author 88250
* @version 1.0.0.3, Mar 20, 2008
*/
public class ImageUtils {
/** * Return all of the pixel values of sepecified codeimage .* @param image the sepecified image
* @param width width of the image
* @param height height of the image
* @return */ public static int[] getPixels(Image image, int width, int height) {
int[] pixels = new int[width * height];
try {
new PixelGrabber(image, 0, 0, width, height, pixels, 0, width).grabPixels();
} catch (InterruptedException ex) {
Logger.getLogger(ImageUtils.class.getName()).
log(Level.SEVERE, null, ex);
}
return pixels;
}
資源來自:
可以使用正則表達(dá)式+中文字符編碼區(qū)間驗(yàn)證一個字符串中是否包含漢字
代碼如下:
public static void main(String[] args) {
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
//System.out.println(regEx);
String str = "中文fdas ";
//System.out.println(str);
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
while (m.find()) {
for (int i = 0; i = m.groupCount(); i++) {
count = count + 1;
}
}
System.out.println("共有 " + count + "個 ");
}
圖片上的文字是沒法讀取的,以為這涉及到圖像處理。非常非常復(fù)雜!因?yàn)槿绻惴且x取圖片上的文字,不是幾行代碼可以搞定的,首相從matlaB開始學(xué),了解什么是圖像處理。然后再開發(fā)相應(yīng)的jar包。當(dāng)然,你也可以使用相關(guān)的軟件工具,比如識圖軟件,通過讀取軟件的反饋也算是讀取了圖片上的文字
java文字識別程序的關(guān)鍵是尋找一個可以調(diào)用的OCR引擎。tesseract-ocr就是一個這樣的OCR引擎,在1985年到1995年由HP實(shí)驗(yàn)室開發(fā),現(xiàn)在在Google。tesseract-ocr 3.0發(fā)布,支持中文。不過tesseract-ocr 3.0不是圖形化界面的客戶端,別人寫的FreeOCR圖形化客戶端還不支持導(dǎo)入新的 3.0 traineddata。但這標(biāo)志著,現(xiàn)在有自由的中文OCR軟件了。
java中使用tesseract-ocr3.01的步驟如下:
1.下載安裝tesseract-ocr-setup-3.01-1.exe(3.0以上版本才增加了中文識別)
2.在安裝向?qū)е锌梢赃x擇需要下載的語言包。
3.到網(wǎng)上搜索下載java圖形處理所需的2個包:jai_imageio-1.1-alpha.jar,swingx-1.6.1.jar
4.java程序清單:
文字識別私有化部署方案
可部署至「本地服務(wù)器」的文字識別服務(wù),支持主流 CPU/GPU 環(huán)境及國產(chǎn)化系統(tǒng)部署,通用場景、卡證、票據(jù)、iOCR 等各類 OCR 模型及自定義平臺均可提供容器化部署包,在專有網(wǎng)絡(luò)環(huán)境下一鍵部署應(yīng)用,保障數(shù)據(jù)私密性。同時(shí),可提供通用型一體機(jī)或國產(chǎn)化一體機(jī),軟硬一體交付,開箱即用,統(tǒng)一維保
快捷部署
容器化打包,支持本地物理機(jī)、私有云等多種部署方式,提供一鍵部署工具和常用運(yùn)維工具,快速接入、高效運(yùn)維
數(shù)據(jù)安全
專有網(wǎng)絡(luò)環(huán)境下本地化部署,數(shù)據(jù)無需公網(wǎng)上傳,實(shí)現(xiàn)業(yè)務(wù)網(wǎng)絡(luò)公私分離,保障企業(yè)核心生產(chǎn)數(shù)據(jù)的私密性要求
適配廣泛
CPU 及 GPU 環(huán)境均可部署,主流 GPU 顯卡類型均已適配,并可支持國產(chǎn)化系統(tǒng)部署
授權(quán)靈活
根據(jù)QPS和使用期限進(jìn)行授權(quán),可自由選擇不同QPS配置,靈活適應(yīng)不同場景、不同業(yè)務(wù)的并發(fā)量需求
成為開發(fā)者
三步完成賬號的基本注冊與認(rèn)證:
STEP1:點(diǎn)擊百度AI開放平臺導(dǎo)航右側(cè)的控制臺,選擇需要使用的AI服務(wù)項(xiàng)。若為未登錄狀態(tài),將跳轉(zhuǎn)至登錄界面,請您使用百度賬號登錄。如還未持有百度賬戶,可以點(diǎn)擊此處注冊百度賬戶。
STEP2:首次使用,登錄后將會進(jìn)入開發(fā)者認(rèn)證頁面,請?zhí)顚懴嚓P(guān)信息完成開發(fā)者認(rèn)證。注:(如您之前已經(jīng)是百度云用戶或百度開發(fā)者中心用戶,此步可略過)。
STEP3:通過控制臺左側(cè)導(dǎo)航,選擇產(chǎn)品服務(wù)-人工智能,進(jìn)入具體AI服務(wù)項(xiàng)的控制面板(如文字識別、人臉識別),進(jìn)行相關(guān)業(yè)務(wù)操作。
希望能幫到你,謝謝!
這種不是個人可以處理的,也不是java的強(qiáng)項(xiàng),去找提供ocr api的廠商吧。
分享文章:文字識別java代碼實(shí)現(xiàn) java 文字識別 開源
URL地址:http://aaarwkj.com/article42/hhpchc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、響應(yīng)式網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、動態(tài)網(wǎng)站、云服務(wù)器、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)