》》點贊照雁,收藏+關(guān)注,理財&技術(shù)不迷路《《
Tesserct-OCR是接收image的方式轰豆,image這個方式是PIL處理過的image不翩,而不是我們opencv中數(shù)組類型的image。
"""
驗證碼識別
1.步驟:
? ? 1. 預(yù)處理-去除干擾線和點
? ? 2.不同的結(jié)構(gòu)元素中選擇
? ? 3. Image和numpy array相互轉(zhuǎn)換
? ? 4. 識別和輸出 tess.image_to_string
2. 報錯與處理
當出現(xiàn)該錯誤:raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path
不同系統(tǒng)采用不同策略:
On Linux
? ? sudo apt update
? ? sudo apt install tesseract-ocr
? ? sudo apt install libtesseract-dev
On Mac
? ? brew install tesseract
On Windows
? ? 先下載tesseract包:https://github.com/UB-Mannheim/tesseract/wiki.
? ? 然后修改pytesseract.py中tesseract_cmd指向的路徑:tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
references: https://pypi.org/project/pytesseract/ (INSTALLATION section) and https://github.com/tesseract-ocr/tesseract/wiki#installation
"""
發(fā)現(xiàn)3*3的結(jié)構(gòu)元素處理起來效果不是很好指蚜,那我們換成2*2的結(jié)構(gòu)元素來處理乞巧。
1*2:
2*1:
驗證碼的識別:
最終代碼: