之前使用 sudo apt-get install tesseract-ocr 安装的tesseract-ocr有问题,不能使用psm参数。决定手动编译安装。下面参考别人的安装过程。
安装所需的库
sudo apt-get install libpng12-dev sudo apt-get install libjpeg62-dev sudo apt-get install libtiff4-dev sudo apt-get install gcc sudo apt-get install g++ sudo apt-get install automake
pytesser 调用了 tesseract,因此需要安装 tesseract,安装 tesseract 需要安装 leptonica,否则编译tesseract 的时候出现 "configure: error: leptonica not found"。
以下都是解压编译安装的老步骤:
./configure make -j4 sudo make install
下载安装leptonica
http://www.leptonica.org/download.html 或者
http://code.google.com/p/leptonica/downloads/list
下载安装tesseract
http://code.google.com/p/tesseract-ocr/
最新的是 tesseract-ocr-3.02.02.tar.gz
下载安装 tesseract 的语言数据包
http://code.google.com/p/tesseract-ocr/downloads/list
最新的是 tesseract-ocr-3.01.eng.tar.gz
解压tessdata目录下的文件(9个)到 "/usr/local/share/tessdata"目录下
注意:这个网址下载到的只有一个,不能用,使用中会报错,http://tesseract-ocr.googlecode.com/files/eng.traineddata.gz
下载安装 pytesser
http://code.google.com/p/pytesser/
最新的是 pytesser_v0.0.1.zip
测试pytesser
到pytesser的安装目录,创建一个test.py,python test.py 查看结果。
from pytesser import * #im = Image.open('fnord.tif') #im = Image.open('phototest.tif') #im = Image.open('eurotext.tif') im = Image.open('fonts_test.png') text = image_to_string(im) print text
tesseract 目录还有其他tif文件,也可以复制过来测试,上面测试的tif,png文件正确识别出文字。
pytesser的验证码识别能力较低,只能对规规矩矩不歪不斜数字和字母验证码进行识别。测试了几个网站的验证码,显示 Empty page,看来用它来识别验证码是无望了。
测试发现提高对比度后再识别有助于提高识别准确率。
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(4)
错误记录
1.遇到这个错误
$ tesseract foo.png bar
tesseract: error while loading shared libraries: libtesseract_api.so.3 cannot open shared object file: No such file or directory
You need to update the cache for the runtime linker. The following should get you up and running:
$ sudo ldconfig
2. 使用遇到如下错误
Tesseract Open Source OCR Engine v3.02.02 with Leptonica Error in findTiffCompression: function not present Error in pixReadStreamTiff: function not present Error in pixReadStream: tiff: no pix returned Error in pixRead: pix not read Unsupported image type.
坑爹居然是leptonica1.69的bug,参考:https://bugs.mageia.org/show_bug.cgi?id=10411#c4,坑爹的是居然没有找到组新修复版,不得已我使用leptonica-1.68,可以了。
安装成功的提示:
yunpeng@yunpeng-duitang:~/下载/tesseract-temp$ tesseract
Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.
Single options:
-v --version: version info
--list-langs: list available languages for tesseract engine
参考:
====================================================================================
使用pytesser遇到问题:
Traceback (most recent call last):
File "test.py", line 15, in <module>
pytesser.image_to_string(data)
File "/home/jose/Documentos/Geek/pytesser.py", line 31, in image_to_string
call_tesseract(scratch_image_name, scratch_text_name_root)
File "/home/jose/Documentos/Geek/pytesser.py", line 21, in call_tesseract
proc = subprocess.Popen(args)
File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1213, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
参考:http://code.google.com/p/pytesser/issues/detail?id=2
需要安装tesseract-ocr
sudo apt-get install tesseract-ocr
使用: tesseract test.jpg -l eng
Tesseract是图盲,默认情况下只能看得懂未压缩的TIFF图像,如果直接用tesseract处理其它格式的图片,会报错如下:
name_to_image_type:Error:Unrecognized image type:test.jpg
IMAGE::read_header:Error:Can't read this image type:test.jpg
tesseract:Error:Read of file failed:test.jpg
所以我们需要用ImageMagick来转换图片格式。
安装ImageMagick:
sudo apt-get install imagemagick
使用imagemagick转换图片格式:
convert -compress none -depth 8 -alpha off test.jpg test.tif
使用tesseract,结果保存在out.txt中
tesseract test.tif out
问题:如何让tesseract只识别字母或者数字?
编辑:sudo vi /usr/share/tesseract-ocr/tessdata/configs/digits
tessedit_char_whitelist abcdefghijklmnopqrstuvwxyz0123456789
执行:
tesseract 1.tif out nobatch digits
附录:
Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.
tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
tesseract 图片名 输出文件名 -l 字库文件 -psd pagesegmode 配置文件
例如:
tesseract code.jpg result -l chi_sim -psd 7 nobatch
-l chi_sim 表示用简体中文字库(需要下载中文字库文件,解压后,存放到tessdata目录下去,字库文件扩展名为.raineddata,简体中文字库文件名为: chi_sim.traineddata)
-psd 7 表示告诉tesseract code.jpg图片是一行文本 这个参数可以减少识别错误率. 默认为 3
configfile 参数值为tessdata\configs 和 tessdata\tessconfigs 目录下的文件名
相关推荐
可配置和可扩展的要求应在系统中安装OCR引擎Tesseract(例如,对于ubuntu sudo apt-get install tesseract-ocr)。 在此处遵循Tesseract安装指南。 确保从命令行中可以使用tesseract命令。 安装执行以下操作
以下是使用Python进行OCR的简单示例,使用了pytesseract库,它是Google的Tesseract-OCR的Python封装。 首先,你需要安装pytesseract和相关的OCR工具: pip install pytesseract 你还需要下载并安装Tesseract-OCR...
## go.tesseract go.tesseract是tesseract OCR库的包装器(来自图像/ pdf的文本识别)。 安装和依赖项 go.tesseract具有两个直接依赖关系; go.leptonica和libtesseract 确保已安装 。 go.leptonica具有C库依赖关系...
主要介绍了python3使用Pillow、tesseract-ocr与pytesseract模块的图片识别的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Windows:预编译的二进制文件可以在lib\tesseractocr-master.zip找到。 解压缩所有DLL文件并将其复制到bin\ 。 必须在计算机上安装 。 Linux: sudo apt install tesseract-ocr 。 这还将安装所需的共享库(liblept...
要求(Ubuntu 18.04和20.04)建造制作cmake g ++ libtesseract-dev libgs-dev libxslt1-dev libopencv开发运行Tesseract-ocr 幽灵脚本libxslt1.1 libopencv-core3.2 | libopencv-核心4.2安装及使用要从源代码进行...
Tesseract OCR演示将.pdf文件转换为图像。 使用tesseract将转换后的图像转换为x格式。 去做: 将结果写入数据库。 将tesseract识别的单词和组绘制到图像上。用法Ubuntu 20.04 bash 0_install_and_setup_tools.sh 将...
PDF到TXT 使用Python代码对PDF文件进行OCR识别并将文本导出到TXT文件。 LocalOCR :基于 CloudOCR :基于在Ubuntu上安装LocalOCR apt-get install python-pyocr python-wand imagemagickapt-get install ...
Tesseract OCR文字识别 图片人脸检测(OpenCV版) 图片人脸检测(Dlib版) 视频人脸检测(OpenCV版) 视频人脸检测(Dlib版) 脸部轮廓绘制 数字化妆 视频人脸识别 头像特效合成 性别识别 表情识别 视频...
最近朋友需要一个可以识别图片中的文字的程序,以前做过java验证码识别的程序; 刚好最近在做一个python项目...2.安装tesseract-ocr: apt-get install tesseract-ocr 3.安装pytesseract pip install pytesseract 使用py
Python Opencv 之 使用 teesseract 进行简单的文字识别(包括中文) ...三、下载安装需要 pytesseract 需要的 Tesseract-OCR 工具 特别注意:在使用 pytesseract 中,需要配置 Tesseract-OCR,不然使用不了,报错:Tess
对已识别的文本进行后处理,包括拼写检查 从hOCR文档生成PDF文档 安装: 来源:从下载 Windows :从下载 Fedora :可从 Debian :可从 Ubuntu :可从 OpenSUSE :可从 ArchLinux :可从 汇编: 中记录了从源代码...
1.安装tesseract 在不同的系统中安装tesseract非常容易。为了简便,我们以Ubuntu为例。 在Ubuntu中你仅仅需要运行以下命令: 这将会安装支持3种不同语言的tesseract。 2.安装PyOCR 现在我们还需要安装tesseract的...
基于tesseract 证件识别环境依赖:ubuntu16.04opencv3.4.0numpy1.14.2python2.7PILtesseract 4.0.0相关库安装:sudo apt-get install tesseract-ocrsudo apt-get install libtesseract-devsudo pip install ...
这篇文章主要介绍了python识别文字(基于tesseract)代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 Ubuntu版本: 1.tesseract-ocr安装 sudo apt-get...
4.对指定位置图片进行ocr识别 环境 Ubuntu18.04 Python2.7 所需Python模块 1.aircv 用于识别模板再原始图的位置坐标 pip install aircv 2.Pillow 用于剪裁图片 pip install Pillow 3.Tesseract 文字识别 在此...
##起因 弄这个项目的原因,是目前还没有发现一个比较好用的验证码识别模块,目前的验证码识别主要是基于google的光学字符识别Tesseract-OCR如PyOCR,识别精度有限,对于一些复杂的验证码无法识别 ##目前主要工作 这...
Debian / Ubuntu: sudo apt install tesseract-ocr Arch Linux: sudo pacman -Syu tesseract tesseract-data-eng 更高质量的数据包呢? 根据 : 大多数用户将需要tessdata_fast ,而这将作为Linux发行版的一...
百度地图开发java源码 1.该工具开发基于Ubuntu ...4.本工具云识别基于百度ocr实现,由于作者能力有限,且近期较忙,本地识别准确率难以与百度ocr相媲美,所以电脑连接网络时优先使用百度ocr进行识别。没有网络
弄这个项目的原因,是目前还没有发现一个比较好用的验证码识别模块,目前的验证码识别主要是基于google的光学字符识别Tesseract-OCR如,识别精度有限,对于一些复杂的验证码无法识别 ##目前主要工作 这个项目改造自 #...