linux系统如何使用tess4j(java)进行ocr图片文字识别

1、安装GCC开发环境,从而支持后续程序的编译安装:
yum groupinstall "Development Tools"


2、安装tesseract所需的依赖库
yum -y install libjpeg* libpng* freetype* gd* giflib* libtiff* zlib*

3、安装tesseract和leptonica
(1)首先安装依赖的leptonica库:
wget http://www.leptonica.com/source/leptonica-1.72.tar.gz
tar -xvf leptonica-1.72.tar.gz  
cd leptonica-1.72
./configure && make && make install

(2)编译tesseract了,所用版本 3.04,编译需要automake、libtool,直接用yum安装就可以了。
wget https://github.com/tesseract-ocr/tesseract/archive/3.04.00.tar.gz
mv 3.04.00  Tesseract3.04.00.tar.gz
tar -xvf Tesseract3.04.00.tar.gz  
cd tesseract-3.04.00/
./autogen.sh
./configure
make && make install
 
(3)下载安装英文,中文繁体,中文简体 识别库。
wget --no-check-certificate https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata
wget --no-check-certificate https://github.com/tesseract-ocr/tessdata/raw/master/chi_sim.traineddata 
wget --no-check-certificate https://github.com/tesseract-ocr/tessdata/raw/master/chi_tra.traineddata
                      
cp/mv *.traineddata /usr/local/share/tessdata/

(4)测试

tesseract card.jpg ./b  -psm 3 -l chi_sim+eng   

cat b.txt

注意: 安装完成后,将/usr/local/lib/ 目录下的so文件拷贝到 /usr/lib64/
cp /usr/local/lib/*.so.* /usr/lib64/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 Tesseract OCR进行图片文字识别Java 代码: ```java import java.io.File; import java.io.IOException; import net.sourceforge.tess4j.Tesseract; import net.sourceforge.tess4j.TesseractException; public class OCR { public static void main(String[] args) { File imageFile = new File("image.png"); Tesseract tesseract = new Tesseract(); try { String result = tesseract.doOCR(imageFile); System.out.println(result); } catch (TesseractException e) { System.err.println(e.getMessage()); } } } ``` 在这个示例中,我们使用Tesseract OCR 库来识别名为 `image.png` 的图像文件中的文本。请注意,要使用 Tesseract OCR 库,您需要将其添加到项目的类路径中。 您还需要将以下依赖项添加到您的项目中: ```xml <dependency> <groupId>net.sourceforge.tess4j</groupId> <artifactId>tess4j</artifactId> <version>4.5.1</version> </dependency> <dependency> <groupId>com.github.jai-imageio</groupId> <artifactId>jai-imageio-core</artifactId> <version>1.4.0</version> </dependency> <dependency> <groupId>com.github.jai-imageio</groupId> <artifactId>jai-imageio-jpeg2000</artifactId> <version>1.3.0</version> </dependency> <dependency> <groupId>com.github.jai-imageio</groupId> <artifactId>jai-imageio-metadata</artifactId> <version>1.3.0</version> </dependency> <dependency> <groupId>com.github.jai-imageio</groupId> <artifactId>jai-imageio-impl</artifactId> <version>1.3.0</version> </dependency> ``` 请注意,这些依赖项可能因版本而异。最好查看 Tesseract OCR 库的文档以获取正确的依赖项。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值