【问题标题】:How to extract tables from Image如何从图像中提取表格
【发布时间】:2022-07-15 01:15:39
【问题描述】:

这个 python 模块https://pypi.org/project/ExtractTable/ 和它的网站https://www.extracttable.com/pro.html 可以准确地提取表格,但他们的免费试用有限。我做了很多事情,但结果很糟糕。该网站/python 模块如何生成 100% 准确的表格。该解决方案应该适用于此驱动器链接https://drive.google.com/drive/folders/1v3UDuR7dUFVMR1im7VHTXKqkxTIV9px9?usp=sharing

上可用的这 3 个图像

这是我尝试过的代码,但效果不佳。帮助我准确提取该网站的表格。

import cv2 as cv
import numpy as np
import pytesseract
from pytesseract import Output
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (120,16)

ebl='data/manu.png'
ROI_number=0
image = cv.imread(ebl)
original=image
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
custom_config = r'--oem 3 --psm 6'
details = pytesseract.image_to_data(gray, output_type=Output.DICT, config=custom_config, lang='eng')

total_boxes = len(details['text'])
for sequence_number in range(total_boxes):
    if int(details['conf'][sequence_number]) >30:
        (x, y, w, h) = (details['left'][sequence_number], details['top'][sequence_number], details['width'][sequence_number],  details['height'][sequence_number])
        threshold_img = cv.rectangle(original, (x, y), (x + w, y + h), (0, 255, 0), 2)

        
plotting = plt.imshow(threshold_img)
plt.show()

【问题讨论】:

标签: python opencv python-imaging-library scikit-image python-tesseract


【解决方案1】:

你可以使用我的包:ocr-nanonets-wrapper。

它有无限的免费使用。

使用 pip 下载包: pip install ocr-nanonets-wrapper

获取 API 密钥。此密钥是免费的,可让您无限制地使用该软件包。

  • 转到nanonets.com 并注册
  • 在您的 Nanonets 帐户上,转到我的帐户 -> API 键
  • 复制您的 API 密钥

在下面分享代码以获取表格为 csv -

from nanonets import NANONETSOCR
nanonets = NANONETSOCR()

nanonets.set_token('YOUR_API_KEY')

nanonets.image_to_csv('INPUT_FILE_PATH', filename = 'OUTPUT_FILE_NAME.csv')

您也可以将filename 留空,然后它只会获取您的图像文件名并在其上附加“.csv”。 .csv 输出文件将在您的当前目录中创建。

希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-15
    • 2020-04-09
    • 1970-01-01
    • 2020-05-01
    • 2021-06-12
    • 2019-06-08
    • 1970-01-01
    • 2019-04-29
    相关资源
    最近更新 更多