我有以下問題。我想在 python 中閱讀這些型別的驗證碼:





我做過的最好的代碼是這樣的,但是它無法解決所有這些驗證碼:
import pytesseract
import cv2
import numpy as np
import re
def odstran_sum(img,threshold):
"""Funkce odstrani sum."""
filtered_img = np.zeros_like(img)
labels,stats= cv2.connectedComponentsWithStats(img.astype(np.uint8),connectivity=8)[1:3]
label_areas = stats[1:, cv2.CC_STAT_AREA]
for i,label_area in enumerate(label_areas):
if label_area > threshold:
filtered_img[labels==i 1] = 1
return filtered_img
def preprocess(img_path):
"""Konvertuje do binary obrazku."""
img = cv2.imread(img_path,0)
blur = cv2.GaussianBlur(img, (3,3), 0)
thresh = cv2.threshold(blur, 150, 255, cv2.THRESH_BINARY_INV)[1]
filtered_img = 255-odstran_sum(thresh,20)*255
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
erosion = cv2.erode(filtered_img,kernel,iterations = 1)
return erosion
def captcha_to_string(obrazek):
"""Funkce vrati text z captchy"""
text = pytesseract.image_to_string(obrazek)
return re.sub(r'[^\x00-\x7F] ',' ', text).strip()
img = preprocess(CAPTCHA_NAME)
text = captcha_to_string(img)
print(text)
是否可以改進我的代碼使其能夠閱讀所有這五個示例?非常感謝。
uj5u.com熱心網友回復:
除了撰寫自己的基于類似驗證碼的影像識別神經網路之外,我認為沒有太多需要改進的地方。驗證碼的設計是為了讓計算機很難解碼它們,所以我認為你不會得到完美的結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/368542.html
上一篇:Tensorflow:使用`keras.utils.Sequence`作為輸入時不支持`y`引數
下一篇:如何在每個藍色物件周圍繪制矩形?
