如何从图像中提取表格

问题描述 投票:0回答:1

这个 python 模块 https://pypi.org/project/ExtractTable/ 及其网站 https://www.extracttable.com/pro.html 准确提取表格,但免费试用有限。我做了很多事情,但结果却很差。该网站/Python 模块如何生成 100% 准确的表格。该解决方案应该适用于此驱动器链接上提供的这 3 个图像 https://drive.google.com/drive/folders/1v3UDuR7dUFVMR1im7VHTXKqkxTIV9px9?usp=sharing

这是我尝试过的代码,结果很差。帮我像那个网站一样准确地提取表格。

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个回答
0
投票

您可以使用 Amazon Textract 从文档图像中提取表格。这也是一项付费服务,因此可能不完全是您正在寻找的服务,但我会将其留在这里,以防对其他人有帮助。

您可以使用

pip install amazon-textract-textractor
套餐。

例如,您在上面的链接中共享的文档之一:

from textractor import Textractor
from textractor.data.constants import TextractFeatures
extractor = Textractor(profile_name="default")
document = extractor.analyze_document(
    file_source="./test.png",
    features=[TextractFeatures.TABLES]
)
document.visualize()

您还可以将数据提取到 pandas 数据框中:

document.tables[0].to_pandas(True)

© www.soinside.com 2019 - 2024. All rights reserved.