(有趣小程序) Java OCR 图像识别

        Java图像识别技术使用tess4j技术。

  1. 下载Tess4J-3.2.1-src.zip
  2. 下载tesseract-ocr-setup-3.02.02.exe
        Tess4J-3.2.1-src.zip解压后目录结构如下:

         该工程使用的是Ant构建,首先在build.xml当中增加一句<javac srcdir="src" destdir="bin" />,不然可能无法构建项目。构建项目“File→New→Other”,选择Java Project from Existing Ant Buildfile。

 
        浏览build.xml文件,构建项目。

         构建完成目录如下:

         将lib文件夹下的支持jar导入工程当中,讲win32-x86与win32-x86-64拷贝至bin目录当中。

         安装tesseract-ocr-setup-3.02.02.exe,安装完成如下:

         完成以上步骤,可以写示例代码了。
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:

 
         识别结果如下:

 
         附件无法上传,想要文件的加群吧QQ227297422。

猜你喜欢

转载自aa80303857.iteye.com/blog/2332808