OCR文字检测-tesseract4.0源码安装:ubuntu16.04 +x64+leptonica1.77.0

431 阅读4分钟

 

tesseract-3.0 需要ubuntu-16.04 
tesseract-4.0 需要ubuntu-18.04 (基于LSTM,效果较好),以下是在ubuntu-16.04 下安装tesseract-4.0方法

 

 

1)必要流程

参考官方编译教程github : github.com/tesseract-o…

 

tesseract官网相关视频:

 

                www.youtube.com/watch?v=vOd…

                www.youtube.com/watch?v=WZL…

 

If they are not already installed, you need the following libraries (Ubuntu 16.04/14.04)

[plain] view plain copy

  1. sudo apt-get install g++ # or clang++ (presumably)  
  2. sudo apt-get install autoconf automake libtool  
  3. sudo apt-get install autoconf-archive  
  4. sudo apt-get install pkg-config  
  5. sudo apt-get install libpng12-dev  
  6. sudo apt-get install libjpeg8-dev  
  7. sudo apt-get install libtiff5-dev  
  8. sudo apt-get install zlib1g-dev  

 

if you plan to install the training tools, you also need the following libraries:

[plain] view plain copy

  1. sudo apt-get install libicu-dev  
  2. sudo apt-get install libpango1.0-dev  
  3. sudo apt-get install libcairo2-dev  

 

2)leptonica编译(有2种方式,一种是github源码,一种是压缩包,我使用github源码)

 

[java] view plain copy

  1. sudo apt install git  
  2. git clone github.com/DanBloomber…
  3. cd leptonica  
  4. autoreconf -vi  
  5. ./autobuild  
  6. ./configure  
  7. make   

[java] view plain copy

  1. sudo make install  

3)安装tesseract

[plain] view plain copy

  1. cd  
  2. git clone --depth 1 github.com/tesseract-o…
  3. cd tesseract  
  4. ./autogen.sh  
  5. ./configure --enable-debug  
  6. LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include" make  
  7. sudo make install  
  8. sudo ldconfig  

[plain] view plain copy

  1. tesseract -v  

 

测试效果如下图

4)安装训练文件

[plain] view plain copy

  1. make  
  2. make training  
  3. sudo make training-install  

5)安装调试工具

下载官方的两个jar包,复制piccolo2d-core-3.0.jar and piccolo2d-extras-3.0.jar 到 tesseract/java文件夹下,网址:github.com/tesseract-o…

 

[java] view plain copy

  1. (sudo apt-get install default-jre )
  2. (sudo apt-get install default-jdk )-- 因为我已经装过java,所以这部分安装跳过
  3.  
  4. cd tesseract  
  5. cd java  
  6. make ScrollView.jar  
  7. export SCROLLVIEW_PATH=$PWD  

在535行:~/pro/OCR/tesseract$ vim src/api/tesseractmain.cpp (/tesseract/api/tesseractmain.cpp)找到如下代码

 

插入以下代码

 

[java] view plain copy

  1. api.SetVariable("tessedit_dump_pageseg_images", "true");      
  2. api.SetVariable("textord_show_blobs", "true");   
  3. api.SetVariable("textord_show_boxes", "true");    
  4. api.SetVariable("textord_tabfind_show_blocks", "true");  
  5. api.SetVariable("textord_tabfind_show_reject_blobs", "true");     
  6. api.SetVariable("textord_tabfind_show_initial_partitions", "true");   
  7. api.SetVariable("textord_tabfind_show_partitions", "1");      
  8. api.SetVariable("textord_tabfind_show_initialtabs", "true");      
  9. api.SetVariable("textord_tabfind_show_finaltabs", "true");    
  10. api.SetVariable("textord_tabfind_show_images", "true");   

变成

 

保存。

[plain] view plain copy

  1. cd tesseract  
  2. make  
  3. sudo make install  
  4. sudo ldconfig  

6)下载tessdata语言包

可以单独下载自己所需的,移动到 /usr/local/share/tessdata/ 下,也可下载全部后移动

 

:官网稳定版效果比较好(推荐)下载~ github.com/tesseract-o…

 

[plain] view plain copy

  1. git clone github.com/tesseract-o…
  2. export TESSDATA_PREFIX=/home/XX/tessdata  (默认/usr/local/share/tessdata/)
  3. (export TESSDATA_PREFIX=/home/raini/pro/OCR/tesseract/tessdata)

7)代码方式测试

输入图片:

from PIL import Image
import pytesseract
path = "/home/raini/pro/OCR/chinese_ocr/test_images/511528736050980534.jpg"
img = Image.open(path)
text = pytesseract.image_to_string(img, lang='chi_sim')
print(text)

得到:

合木各证 Calvin kleinJeans

J209767-0-3 春

等 级 : 合 格 晏 二 王
品 牌 : CK JEANS ()`彗…
品 名 : 牛 仔 外 套 5
产 地 : 土 耳 其 制 造 不 二 一
产 号 : J2027/67 巳 佳 河

号 型 : 160/76A 5 n

执 行 标 准 : FZz/T81006-2017
安 全 技 术 类 别 : 符 合 GB18401 C 类
( 非 直 接 接 触 皮 肤 的 产 品 )
面 料 成 分 及 洗 涤 方 法 详 见 内 标
水 洗 产 品

J209767-911-0
检 验 员 : JKT112 〈】囤 S-83

# 2490.00

代 理 商 : 鹏 卫 齐 商 业 ( 上 海 j 有 限 公 司
地 址 : 上 海 市 静 安 区 安 远 路 555 号 12 楼
电 话 :86-21-62322200

 

8)脚本方式测试

[plain] view plain copy

  1. tesseract rorate.png out -l chi_sim+eng  


 

8)测试2

 

[plain] view plain copy

  1. tesseract /home/joy/tesseract/testing/phototest.tif  

关掉一个窗口,就跳出来了!

 

!!!!终于出现官网的图片了!

 

插入翻译:

 

The words found in the image are represented as blue rectangles. There are 3 menus:

MODES sets the mode for what a left-click or selection does. DISPLAY changes the requested displayed content of the window. (Not immediately) OTHER provides a bunch of miscellaneous global actions. If you right-click in the Editor Image window, you can change the values of any of the "new" config variables on the fly. Depending on what you want to change though, a lot of the useful variables are in the old style and cannot be changed this way. Some day, someone will update all the old style variables to new ones.

NOTE that the menus seem rather strange. This is because the tool was originally designed to provide the capability to create ground truthed files, in excruciating detail with labels on the characters, information on the connected components making up each character etc. Most of this functionality is redundant and hasn't been used in over 10 years. Some of the functionality advertised can easily crash the program, but the functionality documented here should work...

To show the characters, deselect DISPLAY/Bounding Boxes, select DISPLAY/Polygonal Approx and then select OTHER/Uniform display.

To zoom in, position the cursor over a word, and roll the mouse scroll wheel away from you 2 or three clicks. Each click doubles the size. To zoom out roll the mouse wheel towards you. If you haven't got a mouse wheel ... you may be out of luck. The Java code needs some work in this area.

Now select MODES/Recog words and click in a word. If you choose the word 'code' (the 2nd word on the 2nd line) then you should get something like this:

 

参考文献

a)leptonica的编译版本

!!!Do not install libleptonica-dev with apt-get, since you manually intsall leptonica later.

使用leptonica的github

www.panhaoo.cn/posts/17508…

github.com/tesseract-o…

github.com/DanBloomber…

github.com/tesseract-o…

使用leptonica压缩包

www.cnblogs.com/jkmiao/p/64…

blog.csdn.net/u012384044/…

www.cnblogs.com/gavanwanggw…

jybaek.tistory.com/620

b)ViewerDebugging

lengerrong.blogspot.jp/2017/03/vie…

 

github.com/tesseract-o…

blog.csdn.net/yazi1297/ar…

blog.csdn.net/tfygg/artic…

 

3)其他参考(tesseract旧版本)

blog.csdn.net/yimingsilen…

blog.csdn.net/yimingsilen…

blog.csdn.net/tuling_rese…

www.letout.cc/archives/ma…

blog.csdn.net/u012476249/…

segmentfault.com/a/119000000…

 

vs编译:

www.polarxiong.com/archives/Te…

github.com/DanBloomber…
groups.google.com/forum/#!top…
jhoci.tistory.com/1

blog.csdn.net/zzb4702/art…

blog.csdn.net/naidoudou/a…


封装tesseract 应用:

www.polarxiong.com/archives/py…
www.polarxiong.com/archives/py…

dmlcoding.com/2017/Tesser…

www.codepalace.org/2017/08/05/…

 

(文章主要来源于这篇博客:blog.csdn.net/u013985291/…

有错请指出,谢谢!