【问题标题】:Python tesseract increase accuracy for OCRPython tesseract 提高了 OCR 的准确性
【发布时间】:2017-04-03 06:29:07
【问题描述】:

我有很简单的图片,但 tesseract 无法给我正确的答案。

代码:

pytesseract.image_to_string(image, lang='eng')

示例图片给出的结果

SARVN PRIM E N EU ROPTICS\nBLU EPRINT

我也尝试将自己的单词添加到字典中,如果它可以使某些东西变得更好,但仍然没有。

pytesseract.image_to_string(image, lang='eng', config="--user-words words.txt")

我的单词表是这样的

SARYN
PRIME
NEUROPTICS
BLUEPRINT

我应该如何解决这个问题,也许我必须在预测之前转换图像?文本颜色可能因几种颜色而异,但背景始终为黑色。

【问题讨论】:

    标签: python machine-learning ocr tesseract python-tesseract


    【解决方案1】:

    在尝试使用 OCR 之前,请尝试反转图像,然后执行二值化/阈值处理以在白色背景上获取黑色文本。

    请参阅this post,了解有关 Python 中图像二值化的提示。

    当然,输入图像中的文本质量越好、越清晰,您的 OCR 结果就会越好。

    我使用外部工具将其更改为白底黑字并得到下图。

    【讨论】:

      【解决方案2】:

      我有一个四步解决方案

      Result
      Smoothing
      Threshold
      Upsample
      +
      Erode

      Pytesseract SARYN PRIME NEUVROPTICS
      BLUEPRINT

      Code:


      import cv2
      import pytesseract
      
      img = cv2.imread('j0nNV.png')
      gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
      blr = cv2.GaussianBlur(gry, (3, 3), 0)
      thr = cv2.threshold(blr, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
      (h_thr, w_thr) = thr.shape[:2]
      s_idx = 0
      e_idx = int(h_thr/2)
      
      for _ in range(0, 2):
          crp = thr[s_idx:e_idx, 0:w_thr]
          (h_crp, w_crp) = crp.shape[:2]
          crp = cv2.resize(crp, (w_crp*2, h_crp*2))
          crp = cv2.erode(crp, None, iterations=1)
          s_idx = e_idx
          e_idx = s_idx + int(h_thr/2)
          txt = pytesseract.image_to_string(crp)
          print(txt)
          cv2.imshow("crp", crp)
          cv2.waitKey(0)
      

      【讨论】:

        猜你喜欢
        • 2021-06-30
        • 1970-01-01
        • 2012-03-17
        • 2019-11-02
        • 1970-01-01
        • 1970-01-01
        • 2018-07-03
        • 1970-01-01
        相关资源
        最近更新 更多