【问题标题】:How to extract tabular data from images?如何从图像中提取表格数据?
【发布时间】:2019-08-29 05:22:03
【问题描述】:

我有一些示例图片。如何从图像中提取表格数据并存储为 JSON 格式?

【问题讨论】:

  • Google python OCR 库。
  • pytesseract.image_to_string(img, lang='eng')

标签: python opencv machine-learning nlp computer-vision


【解决方案1】:

使用pytesseract。代码将是这样的。 你可以尝试不同的修改。 我的代码可能无法解决整个问题。这只是一个示例代码,这适用于黑色文本,但对于蓝色和任何其他颜色,您必须相应地创建一个蒙版,然后提取该数据。

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter

im = Image.open("temp.jpg")

maxsize = (2024, 2024)
im=im.thumbnail(maxsize, PIL.Image.ANTIALIAS) 

im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)

im = enhancer.enhance(2)
im = im.convert('1')

im.save('mod_file.jpg')
text = pytesseract.image_to_string(Image.open('mod_file.jpg'))
print(text)

例如,对于红色检测,您可以参考此post。 得到红色文本后对图像进行二值化然后运行

text = pytesseract.image_to_string(Image.open('red_text_file.jpg'))

同样,您必须对蓝色等执行相同的过程。 我相信你可以很容易地尝试自己做,只是玩一些价值观。

【讨论】:

  • 感谢您的回答,但我没有得到确切的数据。字符。 short int int lone int float double 8 long double 12 |意义少啊啊啊=无效
猜你喜欢
  • 2020-05-01
  • 2019-06-08
  • 2022-07-15
  • 2022-07-15
  • 2020-04-09
  • 1970-01-01
  • 1970-01-01
  • 2022-10-09
  • 1970-01-01
相关资源
最近更新 更多