[Python] 識別影象中的文字--pytesser模組
阿新 • • 發佈:2019-01-28
安裝pytesser
安裝PIL
pip2 install numpy pip2 install pillow
-
C:\Python27\ArcGIS10.2\Lib\site-packages\pytesser
將
pytesser.py
檔名修改為__init__.py
開啟第三步的檔案
import Image #修改為 from PIL import Image tesseract_exe_name = 'tesseract' # 修改為 tesseract_exe_name = r'C:\Python27\ArcGIS10.2\Lib\site-packages\pytesser\tesseract' # Name of executable to be called at command line
測試
import pytesser # 未報錯即成功
使用
識別簡單英文與數字可以,識別中文不行
from pytesser import * # 法一 im = Image.open(r'E:\user\Desktop\test_cmd.png') text = image_to_string(im) print text # 法二 text = image_file_to_string(r'E:\user\Desktop\test_cmd.png',graceful_errors=True) print text # 使用ImageEnhance可以增強圖片的識別率 image = Image.open(r'E:\user\Desktop\test_cmd.png') enhancer = ImageEnhance.Contrast(image) image_enhancer = enhancer.enhance(4) print image_to_string(image_enhancer)