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

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


1)必要流程

参考官方编译教程githubhttps://github.com/tesseract-ocr/tesseract/wiki/Compiling#linux

tesseract官网相关视频:

                https://www.youtube.com/watch?v=vOdnt2h1U8U
                https://www.youtube.com/watch?v=WZLJucXZy-g

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 https://github.com/DanBloomberg/leptonica   
  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 https://github.com/tesseract-ocr/tesseract.git  
  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文件夹下,网址:https://github.com/tesseract-ocr/tesseract/wiki/ViewerDebugging


[java]  view plain  copy
  1. (sudo apt-get install default-jre )
  2. (sudo apt-get install default-jdk )-- 因为我已经装过java,所以这部分安装跳过


  3. cd tesseract  
  4. cd java  
  5. make ScrollView.jar  
  6. 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/ 下,也可下载全部后移动

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


[plain]  view plain  copy
  1. git clone https://github.com/tesseract-ocr/tessdata  
  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

https://www.panhaoo.cn/posts/1750844891/

https://github.com/tesseract-ocr/tesseract/issues/1043

https://github.com/DanBloomberg/leptonica/issues/197

https://github.com/tesseract-ocr/tesseract/issues/1000

使用leptonica压缩包

http://www.cnblogs.com/jkmiao/p/6417167.html

http://blog.csdn.net/u012384044/article/details/77979803

http://www.cnblogs.com/gavanwanggw/p/7219503.html

http://jybaek.tistory.com/620

b)ViewerDebugging

https://lengerrong.blogspot.jp/2017/03/viewerdebugging-tesseract-ocr-on-ubuntu.html(可行,步骤2,出错点:复制两个jar包的时候要复制好,我第一遍的时候可能复制不好)


https://github.com/tesseract-ocr/tesseract/wiki/ViewerDebugging 
http://blog.csdn.net/yazi1297/article/details/54706390 
http://blog.csdn.net/tfygg/article/details/63262396

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

http://blog.csdn.net/yimingsilence/article/details/51276138

http://blog.csdn.net/yimingsilence/article/details/51353772

http://blog.csdn.net/tuling_research/article/details/53543673

http://www.letout.cc/archives/macosx-compling-and-install-tesseract.html

http://blog.csdn.net/u012476249/article/details/53423193

https://segmentfault.com/a/1190000007267921


vs编译:

https://www.polarxiong.com/archives/Tesseract-3-05%E5%8F%8A%E4%B9%8B%E5%90%8E%E7%89%88%E6%9C%AC%E7%BC%96%E8%AF%91%E7%94%9F%E6%88%90%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93DLL.html

https://github.com/DanBloomberg/leptonica/issues/237
https://groups.google.com/forum/#!topic/tesseract-ocr/r6bL_KLlcyE
http://jhoci.tistory.com/1

http://blog.csdn.net/zzb4702/article/details/51760678

http://blog.csdn.net/naidoudou/article/details/70225849


封装tesseract 应用

https://www.polarxiong.com/archives/python-pytesser-tesseract.html
https://www.polarxiong.com/archives/python-tesseract-verification-code.html

http://dmlcoding.com/2017/TesseractBasic/

http://www.codepalace.org/2017/08/05/Tesseract-OCR-with-Python/


(文章主要来源于这篇博客:https://blog.csdn.net/u013985291/article/details/78113857)感谢感谢!

有错请指出,谢谢!


猜你喜欢

转载自blog.csdn.net/lovebyz/article/details/80814772