day_6:验证码识别
生活随笔
收集整理的這篇文章主要介紹了
day_6:验证码识别
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、普通圖形驗(yàn)證碼
1、相關(guān)庫安裝(MAC)
brew install imagemagick brew install tesseract --with-all-languages pip3 install tesserocr pillow?導(dǎo)入tesserocr報(bào)錯(cuò)和解決辦法
# 導(dǎo)入tesserocr報(bào)錯(cuò) 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'))如果圖像識(shí)破不出來就需要先轉(zhuǎn)灰度再二值化處理
# 轉(zhuǎn)灰度 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)處理前:? ? ? ? ?處理后:
二、極驗(yàn)滑動(dòng)驗(yàn)證碼(Selenium、ChromeDriver、Chrome)
?
三、點(diǎn)觸驗(yàn)證碼
四、微博宮格驗(yàn)證碼
五、12306驗(yàn)證碼
轉(zhuǎn)載于:https://www.cnblogs.com/jp-mao/p/10046809.html
總結(jié)
以上是生活随笔為你收集整理的day_6:验证码识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线上bug分析
- 下一篇: 常用作图与图片处理工具