day_6:验证码识别
生活随笔
收集整理的這篇文章主要介紹了
day_6:验证码识别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、普通圖形驗證碼
1、相關庫安裝(MAC)
brew install imagemagick brew install tesseract --with-all-languages pip3 install tesserocr pillow?導入tesserocr報錯和解決辦法
# 導入tesserocr報錯 import tesserocr !strcmp(locale, "C"):Error:Assert failed:in file baseapi.cpp, line 203# 解決辦法 import locale locale.setlocale(locale.LC_ALL, 'C') import tesserocr?事例測試(方法一比方法二精確度好)
# 方法一 import locale locale.setlocale(locale.LC_ALL, 'C') import tesserocr from PIL import Imageimage = Image.open('/Users/huangjunyi/Desktop/code.jpg') result = tesserocr.image_to_text(image) print(result)# 方法二 import locale locale.setlocale(locale.LC_ALL, 'C') import tesserocrprint(tesserocr.file_to_text('/Users/huangjunyi/Desktop/code.jpg'))如果圖像識破不出來就需要先轉灰度再二值化處理
# 轉灰度 image = image.convert('L') image.show() import locale locale.setlocale(locale.LC_ALL, 'C') import tesserocr from PIL import Imagethreshold = 140 # 二值化的閥值 table = [] image = Image.open('/Users/huangjunyi/Desktop/code.jpg') image = image.convert('L') # 灰度化for i in range(256):if i < threshold:table.append(0)else:table.append(1)image = image.point(table, '1')image.show()result = tesserocr.image_to_text(image) print(result)處理前:? ? ? ? ?處理后:
二、極驗滑動驗證碼(Selenium、ChromeDriver、Chrome)
?
三、點觸驗證碼
四、微博宮格驗證碼
五、12306驗證碼
轉載于:https://www.cnblogs.com/jp-mao/p/10046809.html
總結
以上是生活随笔為你收集整理的day_6:验证码识别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线上bug分析
- 下一篇: 常用作图与图片处理工具