日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【附源码模型】战网验证码识别

發(fā)布時(shí)間:2024/3/26 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【附源码模型】战网验证码识别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. 樣本采集

首先當(dāng)然是采集圖片了,對(duì)接通用模型上懟樣本就是了。

for i in range(100000):sess.headers = {"User-Agent": ua.random}sess.proxies = get_proxy()# print(get_proxy())before_url = "https://www.battlenet.com.cn/login/zh/"before_resp = sess.get(before_url)before_html = Selector(before_resp.text)csrf_token = before_html.xpath('//input[@name="csrftoken"]/@value').extract_first()session_timeout = before_html.xpath('//input[@name="sessionTimeout"]/@value').extract_first()captcha_url = "https://www.battlenet.com.cn/login/captcha.jpg"captcha_resp = sess.get(captcha_url)captcha_bytes = captcha_resp.contentprint(captcha_bytes)captcha_text = requests.post("http://127.0.0.1:19952/captcha/v3", data=captcha_bytes).json()['message']payload = {"accountName": "00000","password": ".","srpEnabled": "true","upgradeVerifier": "","useSrp": "true","publicA": public_a,"clientEvidenceM1": client_evidence_m1,"persistLogin": "on","captchaInput": captcha_text,"csrftoken": csrf_token,"sessionTimeout": session_timeout}resp_submit = sess.post(before_url, data=payload)if "找不到該暴雪游戲通行證" in resp_submit.text:tag = hashlib.md5(captcha_bytes).hexdigest()name = "{}_{}.png".format(captcha_text, tag)print('正確')true_count += 1with open(os.path.join(target_dir, name), "wb") as f:f.write(captcha_bytes)else:print('錯(cuò)誤')false_count += 1# print(before_resp.text)print(true_count+false_count, captcha_text, true_count / (true_count+false_count))

采集代碼有所省略,如下圖所示,采集到正確標(biāo)注的樣本。

2. 訓(xùn)練

打開訓(xùn)練工具
(地址:https://github.com/kerlomz/captcha_trainer)
具體教程可參考:https://www.jianshu.com/p/80ef04b16efc

  • 首先輸入項(xiàng)目名,按下回車將自動(dòng)生成如圖后綴
  • 在樣本區(qū)域內(nèi)導(dǎo)入第一步收集到的樣本
  • 網(wǎng)絡(luò)部分會(huì)根據(jù)導(dǎo)入的樣本自動(dòng)配置,打包樣本即可,如下圖:
  • 打包完成點(diǎn)擊 【開始訓(xùn)練】即可,如下圖:
  • 如圖所示,已經(jīng)開始訓(xùn)練
  • 驗(yàn)證碼使用

    部署項(xiàng)目:https://github.com/kerlomz/captcha_platform
    編譯版(一鍵部署):https://github.com/kerlomz/captcha_platform/releases
    啟動(dòng)成功如圖:

    調(diào)用如圖:

    如圖可見,單次識(shí)別速度在10ms以內(nèi),平均8ms,屬業(yè)內(nèi)領(lǐng)先水準(zhǔn)。

    對(duì)接官網(wǎng)測試結(jié)果:

    測了13次全對(duì),識(shí)別率想必差不了。

    模型下載

    https://github.com/kerlomz/captcha_platform/releases

    后記

    順便宣傳一波麻瓜OCR識(shí)別
    https://pypi.org/project/muggle-ocr/1.0/
    這是一個(gè)OCR和驗(yàn)證碼皆可識(shí)別的本地識(shí)別模塊,使用簡單,pip安裝,三行代碼即可調(diào)用。

    import time# 第一步:導(dǎo)入包 import muggle_ocr# 第二步:初始化;model_type 包含了 ModelType.OCR/ModelType.Captcha 兩種 sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.OCR)# ModelType.Captcha 可識(shí)別光學(xué)印刷文本 with open(r"test1.png", "rb") as f:b = f.read() for i in range(5):st = time.time()# 第三步: 調(diào)用(識(shí)別普通OCR)text = sdk.predict(image_bytes=b)print(text, time.time() - st)# ModelType.Captcha 可識(shí)別4-6位驗(yàn)證碼 sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha) with open(r"test2.jpg", "rb") as f:b = f.read() for i in range(5):st = time.time()# 第三步: 調(diào)用(識(shí)別驗(yàn)證碼)text = sdk.predict(image_bytes=b)print(text, time.time() - st)

    喜歡的各位可以加QQ群:857149419

    總結(jié)

    以上是生活随笔為你收集整理的【附源码模型】战网验证码识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。