python圖像識別--驗證碼


1、pip3 install pyocr

2、pip3 install pillow or easy_install Pillow

3、安裝tesseract-ocr:http://jaist.dl.sourceforge.net/project/tesseract-ocr-alt/tesseract-ocr-setup-3.02.02.exe,安裝在C:\Program Files\下

4、要求python默認安裝在C盤

5、找到 pytesseract.py 更改 tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract.exe'

代碼:

# !/usr/bin/python3.4
# -*- coding: utf-8 -*-

import pytesseract
from PIL import Image

image = Image.open('../jpg/code.png')
code = pytesseract.image_to_string(image)
print(code)

  

 

 

 

 

 

 

如果出現錯誤:

'str' does not support the buffer interface 

 

將 `pytesseract.py` 中的下面語句更換:

1 lines = error_string.splitlines()
2 #error_lines = tuple(line for line in lines if line.find('Error') >= 0)
3 error_lines = tuple(line.decode('utf-8') for line in lines if line.find(b'Error') >= 0)
4 if len(error_lines) > 0:
5     return '\n'.join(error_lines)
6 else:
7     return error_string.strip()

如果要識別更多的文字,需要在安裝tesseract-ocr的時候選擇全部語言,也就1.3G

識別精度不是很高,要不就是現在的驗證碼太變態,人為也看不出來是什么

推薦機器學習驗證碼:http://www.cnblogs.com/beer/p/5672678.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM