从OCR图像文件检索文本时提高文本准确性

时间:2019-05-05 08:41:55

标签: ocr python-tesseract

我正在尝试读取多个图像并从中提取一些特定的文本。 我正在使用pytesseract和OpenCV实现相同的目的。我在下面的代码中尝试了两个图像,它似乎在一个图像上起作用,但在另一个图像上却不起作用。

代码:

    img = cv2.imread(img_path)
    img = cv2.resize(img, None, fx=3.0, fy=3.0, interpolation=cv2.INTER_CUBIC)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    kernel = np.ones((1, 1), np.uint8)
    img = cv2.dilate(img, kernel, iterations=1)
    img = cv2.erode(img, kernel, iterations=1)
    img = cv2.adaptiveThreshold(cv2.medianBlur(img, 3), 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 31, 2)
    img_text = pytesseract.image_to_string(img, lang='eng')

图片1:

enter image description here

输出1: 突出显示的文本在输出中非常清晰,我可以轻松提取它。

enter image description here

由于我需要读取多个文件,因此我正在寻找可以应用于所有图像的常规设置,以便可以将其包装在函数中。

图片2:

enter image description here

输出2:

85029-> 65029

enter image description here

0 个答案:

没有答案
相关问题