python pytesseract庫的實例用法
1、pytesseract需要與安裝在本地的tesseract-ocr.exe文件一起使用。
2、需要注意的是,安裝時必須選擇中文包,默認只支持英文識別。
安裝命令pip install pytesseract實例
import pytesseractfrom PIL import Imagetext = pytesseract.image_to_string(Image.open(r'd:Desktop39DEE621-40EA-4ad1-90CC-79EB51D39347.png'))print(text)
識別結果輸出
Using Tesseract OCR with Python# import the necessary packagesfrom PIL import Imageimport pytesseractimport ergperseimport cv2import os # construct the argument parse and parse the argumentsap = argparse.ArgunentParser()ap.add_argument('-i', '--image', required-True,help='path to input image to be OCR’d')ap.add_argument('-p', '--preprocess', typesstr, default='thresh',helpe'type of preprocessing to be done')args = vars (ap.parse_args())
實例擴展:
Python使用pytesseract庫識別圖片文字
準備
首先需在本機安裝Tesseract客戶端,然后安裝pytesseract庫:
pip install pytesseract
沒安裝過PIL的也要安裝一下,因為所調用的第一個參數是由Image類返回:
pip install PILLOW
實例
import pytesseractfrom PIL import Imageimg = Image.open('D://aa.jpg')text = pytesseract.image_to_string(img, lang='chi_sim')print(text)
到此這篇關于python pytesseract庫的實例用法的文章就介紹到這了,更多相關python pytesseract庫是什么內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!