【发布时间】:2019-11-25 07:01:02
【问题描述】:
我正在尝试将许多 PDF 文档转换为 R 中的文本,以便使用字符串解析和正则表达式从中提取一组代码。我正在使用来自tesseract 库的ocr,虽然它适用于许多页面,但它确实遗漏了很多我需要的信息。
我发现问题是图像/PDF 中的换行符不一致。例如:
我正在尝试从左栏中获取代码。我能够成功提取的唯一代码是描述超过一行的代码。
我已经使用magick 尝试了各种pre-processing 技术,但在大多数情况下都失败了。我能够获得代码集的唯一实例是从图像中裁剪右侧,但不幸的是,在我的情况下这不是一个有效的解决方案。
file <- magick::image_read("44F245A2-5FEE-408F-A197-756436A5CAFD.png")
file %>%
magick::image_resize("2000x") %>%
magick::image_convert(type = 'Grayscale') %>%
tesseract::ocr() %>%
cat()
# or
# descriptions in this document.
# 94942C This is a description that takes on multiple lines. It can contain any combination of
# alphanumeric characters or punctuation. Different types of things can go in here and the
# | terpenes Steet gine see
# 272144 This is a description that takes on multiple lines. It can contain any combination of
# eee
# length of the description could be anywhere from 1 line to 5 lines of text.
# E76744 This is a description that takes on multiple lines. It can contain any combination of
# alphanumeric characters or punctuation. Different types of things can go in here and the
# [terpenes Steet gine see
# K77744 This is a description that takes on multiple lines. It can contain any combination of
# alphanumeric characters or punctuation. Different types of things can go in here and the
# | terrane een Steet gine seem
# 172744 This is a description that takes on multiple lines. It can contain any combination of
# Se
# length of the description could be anywhere from 1 line to 5 lines of text.
# A71744 This is a description that takes on multiple lines. It can contain any combination of
# alphanumeric characters or punctuation. Different types of things can go in here and the
# | teammates Steet gine see
理想情况下,我希望能够从上述链接中的图像中获取所有代码。任何帮助都会很棒。
【问题讨论】:
-
问题是文字有下划线。 Tesseract 难以检测带有下划线的文本行。也许您可以尝试使用 Leptonica 或类似的东西来检测和删除取消划线。
标签: r image-processing imagemagick ocr tesseract