- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从 python
中的图像中提取文本.为了做到这一点,我选择了 pytesseract
.当我尝试从图像中提取文本时,结果并不令人满意。我也经历过this并实现了列出的所有技术。然而,它的表现似乎并不好。
图片:
代码:
import pytesseract
import cv2
import numpy as np
img = cv2.imread('D:\\wordsimg.png')
img = cv2.resize(img, None, fx=1.2, fy=1.2, interpolation=cv2.INTER_CUBIC)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1,1), np.uint8)
img = cv2.dilate(img, kernel, iterations=1)
img = cv2.erode(img, kernel, iterations=1)
img = cv2.threshold(cv2.medianBlur(img, 3), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
txt = pytesseract.image_to_string(img ,lang = 'eng')
txt = txt[:-1]
txt = txt.replace('\n',' ')
print(txt)
输出:
t hose he large form might light another us should took mountai house n story important went own own thought girl over family look some much ask the under why miss point make mile grow do own school was
即使是 1 个不需要的空间也会花费我很多钱。我希望结果是 100% 准确的。任何帮助,将不胜感激。谢谢!
最佳答案
我将调整大小从 1.2 更改为 2 并删除了所有预处理。我用 psm 11 和 psm 12 得到了很好的结果
import pytesseract
import cv2
import numpy as np
img = cv2.imread('wavy.png')
# img = cv2.resize(img, None, fx=1.2, fy=1.2, interpolation=cv2.INTER_CUBIC)
img = cv2.resize(img, None, fx=2, fy=2)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((1,1), np.uint8)
# img = cv2.dilate(img, kernel, iterations=1)
# img = cv2.erode(img, kernel, iterations=1)
# img = cv2.threshold(cv2.medianBlur(img, 3), 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
cv2.imwrite('thresh.png', img)
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
for psm in range(6,13+1):
config = '--oem 3 --psm %d' % psm
txt = pytesseract.image_to_string(img, config = config, lang='eng')
print('psm ', psm, ':',txt)
config = '--oem 3 --psm %d' % psm
线路使用
string interpolation (%) operator替换
%d
带整数 (psm)。我不确定是什么
oem
确实如此,但我已经养成了使用它的习惯。更多关于
psm
在这个答案的最后。
psm 11 : those he large form might light another us should name
took mountain story important went own own thought girl
over family look some much ask the under why miss point
make mile grow do own school was
psm 12 : those he large form might light another us should name
took mountain story important went own own thought girl
over family look some much ask the under why miss point
make mile grow do own school was
psm
是页面分割模式的缩写。我不确定不同的模式是什么。您可以从描述中了解代码的含义。您可以从
tesseract --help-psm
获取列表
Page segmentation modes:
0 Orientation and script detection (OSD) only.
1 Automatic page segmentation with OSD.
2 Automatic page segmentation, but no OSD, or OCR. (not implemented)
3 Fully automatic page segmentation, but no OSD. (Default)
4 Assume a single column of text of variable sizes.
5 Assume a single uniform block of vertically aligned text.
6 Assume a single uniform block of text.
7 Treat the image as a single text line.
8 Treat the image as a single word.
9 Treat the image as a single word in a circle.
10 Treat the image as a single character.
11 Sparse text. Find as much text as possible in no particular order.
12 Sparse text with OSD.
13 Raw line. Treat the image as a single text line,
bypassing hacks that are Tesseract-specific.
关于python - Pytesseract 提高 OCR 准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64099248/
根据 Wikipedia 的说法,“拉丁文打字文本的准确识别现在被认为在很大程度上解决了可以提供清晰成像的应用程序(例如扫描打印文档)的问题。”但是,它没有给出引用。 我的问题是:这是真的吗?当前最先
我在将包含文本图像的 JPG 文件转换为文本文件时遇到问题。我尝试了 ABBYY 的 OCR SDK 和其他一些 OCR 来源,但没有一个包含格鲁吉亚语。 你能告诉我是否有任何可用于格鲁吉亚语的 OC
有人给了我一大堆惊人的信息。它是 200MB 的 .tiff 扫描公告图像,可以追溯到 40 年代。我想将其数字化,但我对 OCR 一无所知。一些早期的 Material 几乎无法被人类阅读,更不用说
我正在尝试通过 python-tesseract 使用 tesseract-OCR 来读取看起来像这样的低分辨率字体: 不幸的是,该图像返回 ZIJZHZI 我认为分辨率太低,这会导致问题。我试过放大
OCR 软件是否能够可靠地将如下图像转换为值列表? 更新: 更详细的任务如下: 我们有一个客户端应用程序,用户可以在其中打开报告。此报告包含一个值表。 但并不是每个报告看起来都一样——不同的字体、不同
我正在尝试使用 Tesseract-OCR检测其中包含纯文本的图像文本,但这些文本具有名为Journal 的手写字体。 例子: 结果不是最好的: Maxima! size` W (35) 有没有可能改
我已经开始了一个简单的项目,它必须获得一个包含带有上标的文本的图像,然后通过使用 OCR(目前我正在使用 tesseract)它必须识别上标字符 + 正常字符。 例如,我们有一个化学方程式,例如 Cl
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我目前正在研究 OCR(波斯语), 尽管“fas.traineddata”在tessdata中可用,但是当我使用以下命令时,什么也没发生: import pytesseract from PIL im
我对文本片段中下标和上标的一般识别有疑问。 示例图片: 我使用 Tesseract 4.1.1 和 https://github.com/tesseract-ocr/tessdata_best 下可用
在过去的 3 个月里,我一直在尝试训练 Tesseract 通过识别我拥有的图像集合,由于真正的缺乏 正确的文档,以及非常高的复杂性,我开始 放弃将 Tesseract 作为解决方案。 我正在寻找一种
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 12 个月前关闭。 Improve this
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
下面是我的电表读数 52425.5(粗略)的图片: 什么程序/技术可以帮助我自动抄表?备注: 这是较为清晰的图像之一。许多图像都有静态。我可以忽略(让程序说“错误”)带有太多静态的图片。 相机有一个固
大写字母OCR(光学字符识别)的常见错误有哪些? 例如FOR -> FOB 最佳答案 要获得最准确的答案,最好使用针对您的问题的特定数据样本自行测试。不同字符/单词组合的错误率可能有很大差异,具体取决
对于我想教 Tesseract 将复选框识别为单词的客户。当 Tesseract 应该识别一个空的复选框时,它工作得很好。 此命令与 this 结合使用教程就像一个魅力,Tesseract 能够找到空
我正在使用 Tesseract OCR将扫描的 PDF 转换为纯文本。总体而言,它非常有效,但我对扫描文本的顺序有疑问。带有表格数据的文档似乎是逐列向下扫描,而更自然的方式是逐行扫描。一个非常小的例子
在哪里可以找到 cube 的 tesseract ocr 土耳其语扩展模式? 文件: tr.cube.fold tr.cube.lm tr.cube.nn tr.cube.params tr.cube
我正在编写一个用于训练 Tesseract OCR 图像的生成器。 在为 Tesseract OCR 的新字体生成训练图像时,最佳值是什么: 新闻部 以磅为单位的字体大小 字体是否应该抗锯齿 边界框是
我的文本带有一些不那么复杂的数学符号,如下所示。 Tesseract OCR 默认无法识别此类数学符号(+-、角度)。我如何通过 tesseract 识别这些数学符号? 最佳答案 只需使用以下语句:
我是一名优秀的程序员,十分优秀!