PyteSeract输出极不准确(MAC)

2024-10-03 06:19:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我通过pip安装了pytesseract,结果非常糟糕

当我搜索它的时候,我想我需要给它更多的数据 但是我找不到tessedata(traineddata)的位置 因为没有类似ProgramFile\t的目录,所以请使用Mac执行OCR

图像的分辨率、字体或大小没有问题。 Image whose result is 'ecient Sh Abu'

因为大而清晰的测试图像工作正常,我认为这是一个缺乏数据的问题。 但任何其他可能的解决方案都是受欢迎的,只要它可以用Python读取文本

请帮帮我


Tags: pip数据图像image目录mac分辨率字体
1条回答
网友
1楼 · 发布于 2024-10-03 06:19:02

I installed pytesseract via pip and its result is terrible.

有时需要对输入图像进行预处理以获得准确的结果

Because large and clear test images work fine, I think it is a problem about lack of data. But any other possible solution is welcomed as long as it can read text with Python.

你可以说缺乏数据是一个问题。我想你会发现morphological-transformations很有用

例如,如果我们应用close操作,结果将是:

enter image description here

该图像看起来与原始发布的图像相似。但是,输出图像中有轻微变化(即语法单词与原始图像略有不同)

现在,如果我们读取输出图像:

English
Grammar Practice
ter K-SAT (1-10)

代码:

import cv2
from pytesseract import image_to_string

img = cv2.imread("6Celp.jpg")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
opn = cv2.morphologyEx(gry, cv2.MORPH_OPEN, None)
txt = image_to_string(opn)
txt = txt.split("\n")
for i in txt:
    i = i.strip()
    if i != '' and len(i) > 3:
        print(i)

相关问题 更多 >