使用OpenCV对pytesseract OCR进行图像预处理

时间:2020-10-05 20:06:22

标签: python opencv ocr python-tesseract

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

enter image description here

我使用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)

结果:

enter image description here

pytesseract会识别以下文本:SMVIN

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

0 个答案:

没有答案