python实现中文图片文字识别--OCR about chinese text--tesseract
0.我的環(huán)境:
win7 32bits
python 3.5
pycharm 5.0?
?
1.相關(guān)庫
安裝pillow:
pip install pillow
安裝tesseract:
tesseract-ocr-setup-3.02.02.exe
自帶了英文語言包,如果需要中文語言包往下找即可。
或者在安裝的時候,在選項lang處,點選chi-sim即可。
安裝完畢后,會兒自動加入系統(tǒng)環(huán)境變量中。
安裝pytesseract:
pip install pytesseract
?
2.修改pytesseract.py原文件
# tesseract_cmd = 'tesseract'
tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract.exe'
#如果不修改,會報錯:FileNotFoundError: [WinError 2] 系統(tǒng)找不到指定的文件。
#f = open(output_file_name)
f = open(output_file_name, encoding='utf-8')
#如果不修改,會兒報錯:UnicodeDecodeError: 'gbk' codec can't decode byte 0xyy in position xxx: illegal multibyte sequence
?
3.小程序,測試一下
1 #coding:utf-8 2 #Test one page 3 import pytesseract 4 from PIL import Image 5 6 def processImage(): 7 image = Image.open('test.png') 8 9 #背景色處理,可有可無 10 image = image.point(lambda x: 0 if x < 143 else 255) 11 newFilePath = 'raw-test.png' 12 image.save(newFilePath) 13 14 content = pytesseract.image_to_string(Image.open(newFilePath), lang='eng') 15 #中文圖片的話,是lang='chi_sim' 16 print(content) 17 18 processImage()?
轉(zhuǎn)載于:https://www.cnblogs.com/flyinghorse/p/5765788.html
總結(jié)
以上是生活随笔為你收集整理的python实现中文图片文字识别--OCR about chinese text--tesseract的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java socket 通讯
- 下一篇: websocket python爬虫_p