我在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
发布于 2020-04-09 11:59:15
要使用数学语言,您应该安装合适的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 \Tesseract-OCR\tessdata。
一开始,尝试使用cli (没有pyhton )来处理您的图像,因为cli有一个完整的选项列表可调。
发布于 2021-04-10 16:15:59
我用了这个密码,它起作用了!
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])
https://stackoverflow.com/questions/61097575
复制相似问题