如何在txt / doc文件中以结构化格式存储图像中提取的文本

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

因为我想从图像中提取文本(它是银行交易声明),我成功地做了。但它给了我原始数据。不是图像中显示的结构化格式。

我试过通过玩他们的顶点来做到这一点。但我刚刚发现以列表格式获得“描述”和“顶点”值。我如何进一步将其保存在doc / txt文件中,结构良好的格式?

我的代码:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="C:\\Users\\...."
client = ImageAnnotatorClient()
list1=[]
list2=[]
def detect_text(Image_path):
    with io.open(Image_path, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)
    response = client.text_detection(image=image)
    web_content = response.web_detection
    web_content.best_guess_labels

    texts = response.text_annotations

    for text in texts:
        #print (text)
        for vertex in text.bounding_poly.vertices:

            list1.append(vertex)

        b=[text.description for text in texts]

    list2=b[1:]
    print(list2)
    print(list1)
detect_text(Image_path)

我有这样的输出:

['IDBI', 'BANK', 'Customer', 'ID'......]
[x: 229
y: 241
, x: 2331
y: 241
, x: 2331
y: 3350
, x: 229
...
...
]

但是预期:在结构化格式中获得银行对账单看起来相似的输出。我可以顺利保存并显示在txt / doc文件中

python-3.x pandas ocr google-vision
1个回答
0
投票

我建议你使用textract库而不是任何其他东西。

参考链接 - https://textract.readthedocs.io/en/stable/

希望这可以帮助。

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