首页 > 解决方案 > 使用 OpenCV 对 pytesseract OCR 进行图像预处理

问题描述

我想使用 pytesseract 为这些图像创建验证码求解器:

在此处输入图像描述

我使用 OpenCV 来预处理我的图像,到目前为止,我有以下内容:

代码:

import pytesseract
import cv2

img = cv2.imread('element.png')
ret,thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
thresh1 = cv2.blur(thresh1, (5, 5))
text = pytesseract.image_to_string(thresh1, lang='eng', config='-c tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz --psm 6')
print(text)

cv2.imshow('Result1 bl', thresh1)
cv2.waitKey(0)

结果:

在此处输入图像描述

并且pytesseract识别文字:SMVIN

我可以更改或添加到我的代码中以获得更准确的结果?

标签: pythonopencvocrpython-tesseract

解决方案


推荐阅读