小编Roh*_*alt的帖子

如何为 Pytesseract 处理这个验证码图像?

我想用 Pytesseract 自动解决像这样的验证码(所有验证码都是红色背景和白色字母)

验证码图像

我一直在尝试处理图像以使 Pytesseract 能够读取它,但没有成功。很高兴收到您处理此图像的想法。这是我的代码:

import cv2
import pytesseract

tessdata_dir_config = '--tessdata-dir "C:\\Program Files\\Tesseract-OCR\\tessdata"'
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'

img = cv2.imread("captcha.png")
img = cv2.resize(img, None, fx=2, fy=2)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
adaptive = cv2.adaptiveThreshold(
    gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 85, 20)
print((pytesseract.image_to_string(img, config=tessdata_dir_config)).strip())
print((pytesseract.image_to_string(gray, config=tessdata_dir_config)).strip())
print((pytesseract.image_to_string(adaptive, config=tessdata_dir_config)).strip())

cv2.imshow("Captcha", img) # Output: IMQW
cv2.imshow("Gray", gray) # Output: IMOW
cv2.imshow("Adaptive", adaptive) # Output: IMOW,

cv2.waitKey(7000)
Run Code Online (Sandbox Code Playgroud)

python ocr python-tesseract

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

ocr ×1

python ×1

python-tesseract ×1