Java图像识别技术使用tess4j技术。
- 下载Tess4J-3.2.1-src.zip
- 下载tesseract-ocr-setup-3.02.02.exe
![](http://dl2.iteye.com/upload/attachment/0120/7974/641503fa-0480-3ee5-8cf3-0752a58076a3.png)
该工程使用的是Ant构建,首先在build.xml当中增加一句<javac srcdir="src" destdir="bin" />,不然可能无法构建项目。构建项目“File→New→Other”,选择Java Project from Existing Ant Buildfile。
![](http://dl2.iteye.com/upload/attachment/0120/7976/2e9393c0-f8b2-3522-aece-4a96c0c12d5c.png)
浏览build.xml文件,构建项目。
![](http://dl2.iteye.com/upload/attachment/0120/7978/6c5b6608-471c-31e9-a30c-d05a0e095cf2.png)
构建完成目录如下:
![](http://dl2.iteye.com/upload/attachment/0120/7980/953c9ea5-beab-3ad5-87b4-3bdd4a2ea32a.png)
将lib文件夹下的支持jar导入工程当中,讲win32-x86与win32-x86-64拷贝至bin目录当中。
![](http://dl2.iteye.com/upload/attachment/0120/7984/5cf59450-64dc-3e08-88a9-fe0c5f59f2a1.png)
安装tesseract-ocr-setup-3.02.02.exe,安装完成如下:
![](http://dl2.iteye.com/upload/attachment/0120/7987/4be15a82-95e1-3159-b6c1-d529ccffcca5.png)
完成以上步骤,可以写示例代码了。
public class TestDemo { @Test public void test() throws Exception { File imageFile = new File("Y:/ocr/test/d.png"); if (imageFile.exists()){ Tesseract1 tess = new Tesseract1(); tess.setDatapath("C:/Program Files (x86)/Tesseract-OCR");//设置Tesseract-OCR路径 tess.setLanguage("eng"); List<String> configs = new ArrayList<>(); configs.add("digits");//设置在Tesseract-OCR\tessdata\configs目录下 tess.setConfigs(configs);//增加设置 String s = tess.doOCR(imageFile); System.out.println("decode is "+s); } } }
识别图片当中的123:
![](http://dl2.iteye.com/upload/attachment/0120/7994/bb7e72a9-8005-38fe-b3d8-903c77ec6ba4.png)
识别结果如下:
![](http://dl2.iteye.com/upload/attachment/0120/7996/577d4783-9412-30ba-8995-3bf67e04654a.png)
附件无法上传,想要文件的加群吧QQ227297422。