JAVA文字识别tess4j使用

Tesseract介绍
Tesseract是一个开源的OCR(Optical Character Recognition,光学字符识别)引擎,可以识别多种格式的图像文件并将其转换成文本,目前已支持60多种语言(包括中文)。 Tesseract最初由HP公司开发,后来由Google维护,目前发布在Googel Project上。

需要提前安装java运行环境。

1.引入tess4j.jar包

       <dependency>
			<groupId>net.sourceforge.tess4j</groupId>
			<artifactId>tess4j</artifactId>
			<version>3.4.0</version>
		</dependency>

2.代码案例

public  void OCR1(){
		File imageFile = new File("C:\\1.png");
		ITesseract instance = new Tesseract();  // JNA Interface Mapping

        //如果采用的不是使用包默认的testdata建议加上一下一行代码:
//        instance.setDatapath("D:\\soft\\OCR\\Tesseract-OCR\\tessdata");

//         ITesseract instance = new Tesseract1(); // JNA Direct Mapp
		instance.setLanguage("chi_sim");//添加中文字库

		try {
			String result = instance.doOCR(imageFile);
			System.out.println(result);
			long startTime = System.currentTimeMillis();
			long endTime = System.currentTimeMillis();
			System.out.println("Time is:" + (endTime - startTime) + " 毫秒");

		} catch (TesseractException e) {
			e.printStackTrace();
		}
	}

3.图片效果

在这里插入图片描述
在这里插入图片描述
识别准确率不是很高,需要针对场景自行训练字库
注意:

Java Runtime Environment, JNA, and JAI-ImageIO are required. Apache Maven and JUnit are used for program building and unit testing. The Tesseract DLLs were built with VS2015 and therefore depend on the Visual C++ 2015 Redistributable Packages.
需要 Java 运行时环境、 JNA和JAI-ImageIO 。Apache Maven和 JUnit用于程序构建和单元测试。Tesseract DLL 是用 VS2015 构建的,因此依赖于 Visual C++ 2015 Redistributable Packages。

编译jar包时如果报错则需要安装Visual C++ 2015 Redistributable Packages。不同版本的jar包根据具体的安装链接库。可以将jar解压查看其中的readme.html文件
在这里插入图片描述
在这里插入图片描述
Microsoft Visual C++ 2013 Redistributable安装地址:https://download.csdn.net/download/weixin_47142014/25898225?spm=1001.2014.3001.5503
Visual C++ 2015 Redistributable Packages安装地址:https://download.csdn.net/download/weixin_47142014/25897406?spm=1001.2014.3001.5503

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Accccccccv

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值