簡體   English   中英

在 Ubuntu 上安裝 Python-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類,並在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? 非常感謝

 sudo apt-get install tesseract-ocr

**在終端中輸入此命令后,它將安裝tesseract **

當我試圖讓 python 使用 Tesseract 時,我發現這個教程非常有用。 但后來我發現這對我的需求來說太簡單了,所以我需要找到另一個解決方案。

我希望這會對你有所幫助!

它首先安裝 gdebi-core,然后用它安裝 .deb 包,以便 gdebi 為我安裝依賴項。 我使用了 Ubuntu 14.04。

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

使用此鏈接進行安裝

一旦你這樣做了,這里是代碼

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM