【问题标题】:pytesseract unable to recognize complex math formula from imagepytesseract 无法从图像中识别复杂的数学公式
【发布时间】:2020-07-20 16:20:40
【问题描述】:

我在 python 中使用 pytesseract 模块,pytesseract 可以识别图像中的文本,但它不适用于包含复杂数学公式的图像,例如根目录下, 推导, 积分数学问题或方程

代码 2.py

# Import modules
from PIL import Image
import pytesseract
import cv2

# Include tesseract executable in your path
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

# Create an image object of PIL library
image = Image.open('23.jpg')

# img = cv2.imread('123.jpg')
# pass image into pytesseract module

# pytesseract is trained in many languages
image_to_text = pytesseract.image_to_string(image, lang='eng+equ')

image_to_text1 = pytesseract.image_to_string(image)

# Print the text
print(image_to_text)
# print(image_to_text1)


# workon digits

输出:

242/33
2x

2x+3X

2X+3x=4

2x?-3x +1=0
(x-1)(x+1) =x2-1
(x+2)/((x+3)(x-4))

7-4=3
V(x/2) =3

2xx—343=6x—3 (x#3)

Jeeta =e* +e

dy 2
S=2?-3
dz ¥

dy = (a? — 3)dx

Input image

【问题讨论】:

  • 请添加一些示例图片和一些示例代码。
  • 这是tesseract 的包装器。一旦你已经安装了它,你有没有在 cli 中尝试过?无论如何,这是很常见的情况,ORC 工具无法识别所有内容。
  • @Sameer 我附上了我的代码和输出,一些数学方程无法正确检测。我能做些什么?提前谢谢你。
  • @yvs 链接无效,先生。
  • @SumitPatel 对不起,使用这个:github.com/tesseract-ocr/tesseract

标签: python-3.x algorithm image-processing


【解决方案1】:

要使用 MATH 语言,您应该为 tesseract 安装正确的语言。在您的情况下,它是来自 https://github.com/tesseract-ocr/tessdata/raw/3.04.00/equ.traineddata 的“equ”。 https://tesseract-ocr.github.io/tessdoc/Data-Files

中描述了可用语言的完整列表

我不熟悉 Windows 的 tesseract 语言安装。但是https://github.com/tesseract-ocr/tesseract/wiki 有一个文档:

如果您想使用其他语言,请下载相应的培训 数据,使用 7-zip 解压,然后将 .traineddata 文件复制到 'tessdata' 目录,可能是 C:\Program Files\Tesseract-OCR\tessdata

首先尝试仅使用 cli(不使用 pyhton)处理您的图像,因为 cli 有一个完整的选项列表来调整。

【讨论】:

    【解决方案2】:

    我使用了这个代码,它奏效了!

    import re
    import cv2
    import pytesseract as tess
    path = (r"C:\Users\10\AppData\Local\Tesseract-OCR\tesseract.exe")
    tess.pytesseract.tesseract_cmd = path
    
    
    png = "Downloads/m.png"
    text = tess.image_to_string(png)
    text.replace(" ", "")
    pattern = re.compile("([0-9][=+-/*])")
    equations = [x for x in text if bool(re.match(pattern, x))]
    
    print(re.findall(r'(.*)', str(text))[0])
    
    

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多