tesseract-3.0 需要ubuntu-16.04
tesseract-4.0 需要ubuntu-18.04 (基于LSTM,效果较好),以下是在ubuntu-16.04 下安装tesseract-4.0方法
1)必要流程
参考官方编译教程github: https://github.com/tesseract-ocr/tesseract/wiki/Compiling#linux
tesseract官网相关视频:
If they are not already installed, you need the following libraries (Ubuntu 16.04/14.04)
- sudo apt-get install g++ # or clang++ (presumably)
- sudo apt-get install autoconf automake libtool
- sudo apt-get install autoconf-archive
- sudo apt-get install pkg-config
- sudo apt-get install libpng12-dev
- sudo apt-get install libjpeg8-dev
- sudo apt-get install libtiff5-dev
- sudo apt-get install zlib1g-dev
if you plan to install the training tools, you also need the following libraries:
- sudo apt-get install libicu-dev
- sudo apt-get install libpango1.0-dev
- sudo apt-get install libcairo2-dev
2)leptonica编译(有2种方式,一种是github源码,一种是压缩包,我使用github源码)
- sudo apt install git
- git clone https://github.com/DanBloomberg/leptonica
- cd leptonica
- autoreconf -vi
- ./autobuild
- ./configure
- make
- sudo make install
3)安装tesseract
- cd
- git clone --depth 1 https://github.com/tesseract-ocr/tesseract.git
- cd tesseract
- ./autogen.sh
- ./configure --enable-debug
- LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include" make
- sudo make install
- sudo ldconfig
- tesseract -v
测试效果如下图
4)安装训练文件
- make
- make training
- 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- (sudo apt-get install default-jre )
- (sudo apt-get install default-jdk )-- 因为我已经装过java,所以这部分安装跳过
- cd tesseract
- cd java
- make ScrollView.jar
- export SCROLLVIEW_PATH=$PWD
插入以下代码
- api.SetVariable("tessedit_dump_pageseg_images", "true");
- api.SetVariable("textord_show_blobs", "true");
- api.SetVariable("textord_show_boxes", "true");
- api.SetVariable("textord_tabfind_show_blocks", "true");
- api.SetVariable("textord_tabfind_show_reject_blobs", "true");
- api.SetVariable("textord_tabfind_show_initial_partitions", "true");
- api.SetVariable("textord_tabfind_show_partitions", "1");
- api.SetVariable("textord_tabfind_show_initialtabs", "true");
- api.SetVariable("textord_tabfind_show_finaltabs", "true");
- api.SetVariable("textord_tabfind_show_images", "true");
- cd tesseract
- make
- sudo make install
- sudo ldconfig
6)下载tessdata语言包
:官网稳定版效果比较好(推荐)下载~ https://github.com/tesseract-ocr/tessdata_best
- git clone https://github.com/tesseract-ocr/tessdata
- export TESSDATA_PREFIX=/home/XX/tessdata (默认/usr/local/share/tessdata/)
- (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)脚本方式测试
- tesseract rorate.png out -l chi_sim+eng
8)测试2
- 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包的时候要复制好,我第一遍的时候可能复制不好)
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)感谢感谢!
有错请指出,谢谢!