首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >pytesseract无法从图像识别复杂的数学公式

pytesseract无法从图像识别复杂的数学公式
EN

Stack Overflow用户
提问于 2020-04-08 09:34:46
回答 2查看 3.8K关注 0票数 1

我在python中使用pytesseract模块,pytesseract从图像中识别文本,但不处理包含复杂数学公式的图像,如根下、派生、积分数学问题或方程

代码2.py

代码语言:javascript
运行
复制
# 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

输出:

代码语言:javascript
运行
复制
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

输入图像

EN

回答 2

Stack Overflow用户

发布于 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有一个完整的选项列表可调。

票数 4
EN

Stack Overflow用户

发布于 2021-04-10 16:15:59

我用了这个密码,它起作用了!

代码语言:javascript
运行
复制
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])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61097575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档