1. 程式人生 > >樹莓派Raspbian系統安裝tesseract-ocr實現OCR

樹莓派Raspbian系統安裝tesseract-ocr實現OCR

第一步安裝依賴:啟動終端依次敲入命令

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

第二步安裝Leptonica

sudo apt-get install libleptonica-dev

第三步安裝tesseract

sudo apt-get install tesseract-ocr

第四步安裝pytesseract

pip install pytesseract

第五步啟動python,新建資料夾輸入以下程式碼

#!/usr/bin/env python

from PIL import Image
import pytesseract
text=Image.open('/home/pi/.local/lib/python2.7/site-packages/pytesseract/test.png')
#print(text)
print(pytesseract.image_to_string(text))

第六步儲存並執行

測試圖片為:(第三步已下載到home/pi/.local/lib/python2.7/site-packages/pytesseract)

測試結果為: