Python-Ubuntu 上的 tesseract 安装

Python-tesseract installation on Ubuntu

我正在尝试从 Ubuntu 15.04 上的 deb 文件安装 python-tesseract 0.9-0.5,但它给出了几个错误。 这就是我所做的:

1- 我在终端上打开文件的路径并写入

sudo dpkg -i python-tesseract_0.9-0.5ubuntu2_i386.deb

2- 在此之后,控制台显示几个错误:

Selecting previously unselected package python-tesseract.
(Reading database ... 349994 files and directories currently installed.)

Preparing to unpack python-tesseract_0.9-0.5ubuntu2_i386.deb ...

Unpacking python-tesseract (0.9-0.5ubuntu2) ...
dpkg: dependency problems prevent configuration of python-tesseract:
 python-tesseract depends on python (<< 2.8).
 python-tesseract depends on python (>= 2.7~).
 python-tesseract depends on liblept4.
 python-tesseract depends on libopencv-core2.4; however:
  Package libopencv-core2.4:i386 is not installed.
 python-tesseract depends on libtesseract3; however:

dpkg: error processing package python-tesseract (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:    
 python-tesseract

3- 只是为了检查,我打开安装文件并提取tesseract.py class,并在python中单独使用。 我是这样打开的:

python tesseract.py 

,但我得到了这个:

Traceback (most recent call last):
  File "tesseract.py", line 28, in <module>
    _tesseract = swig_import_helper()
  File "tesseract.py", line 20, in swig_import_helper
    import _tesseract
ImportError: No module named _tesseract

问题是我想在 python 上使用 tesseract 函数用于光学字符识别应用程序,我知道最好的包装器是 python-tesseract(不是与 pytesseract 相同,我认为)。

我的问题是:如何在 Ubuntu 15.04 上安装 python-tesseract?非常感谢

当我试图让 python 使用 Tesseract 时,我发现这个 tutorial 非常有用。 但后来我发现这对我的需求来说太简单了,所以我需要找到另一个解决方案。

我希望这对你有帮助!

它可以先安装 gdebi-core,然后用它安装 .deb 包,这样 gdebi 就可以为我安装依赖项。我用的是 Ubuntu 14.04.

 sudo apt-get install gdebi-core
 sudo gdebi python-tesseract_0.9-0.5ubuntu2_i386.deb
 sudo apt-get install tesseract-ocr

**在终端中输入此命令后,它将安装 tesseract **

Use this link for installation

一旦你这样做了, 这是代码

from PIL import Image
img="pathToYourImage/img.jpeg"
text = pytesseract.image_to_string(Image.open(img))
print(text)

更新并安装 tesseract-ocr

sudo apt-get update && sudo apt-get install tesseract-ocr

为 python

安装 pytesseract
pip3 install pytesseract

用法

import pytesseract
from PIL import Image
img= "path/img.jpg"
text = pytesseract.image_to_string(Image.open(img))
print(text)