gpt4 book ai didi

ruby - Tesseract 不读取某些数字

转载 作者:数据小太阳 更新时间:2023-10-29 08:02:49 26 4
gpt4 key购买 nike

我开始编写一个简单的脚本来从图像中读取数据。这是我使用 RTesseract 读取它的 Ruby 代码:

require 'rtesseract'
require 'mini_magick'

RTesseract.configure do |config|
config.processor = "mini_magick"
end

image = RTesseract.new("myImage.jpg")
puts image.to_s

我从这张图片开始:

enter image description here

返回的结果是:132B 4

我知道 0 作为 B 返回(我可以解决)。但是后面的308根本没有返回。现在我知道它已经知道如何读取 3 和 0,因为它在第一个数字中就这样做了。我认为它在渲染以下数字时存在一些问题,所以我将其设为黑白。

这是我尝试的第二张图片:

enter image description here

但是返回的结果仍然是:132B 4

最后我剪切了图像并尝试了最后 3 个数字。

这是图片:

enter image description here

但是当我运行脚本时,它没有返回任何结果。关于为什么我无法读取最终数字有什么想法吗?

我正在使用 Ruby 2.2.2、rTesseract 2.1.0 和 MiniMagick 4.5.1。

我正在使用 Tesseract 3.04.01

最佳答案

我在我的 Linux Mint 17 机器上用 tesseract 3.03 测试了你的脚本, Ruby 2.1.5 和 MiniMagick 4.5.1

它还返回 132B 4

如果您确定数字已编码,您可以尝试:

image = RTesseract.new("myImage.jpg", options: :digits)

它返回 13223 4

在没有参数的情况下启动 tesseract 会给你一个可能的选项列表。 “pagesegmode 7”看起来很有趣:7 = 将图像视为单个文本行。

所以:

image = RTesseract.new("myImage.jpg", options: :digits, psm: 7)

它返回 13223 4 3 21 8

对于您的第二张图片,它返回 3 21 8

我认为现在最大的问题是 JPG 伪影非常严重,数字和背景之间的对比度相对较低。 PNG 图像可能会产生更好的结果。

使用 gimp,我将图像调整为 200px 高度,裁剪接近数字以去除一些伪影,使用 150 的颜色/阈值,反转图像并保存为 png :

enter image description here

Rtesseract 返回:

1320 4 3 0 8

使用 Image Magick,此命令可获得相同的结果:

convert myImage.jpg -geometry x200 -threshold 13% -negate myImage.png

关于ruby - Tesseract 不读取某些数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40245844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com