Extracting data from table and saving it. Layout parser package

Viewed 260

I am new in working with python and I am using Melissa Dell's package to extract data from a table image. My image looks like this: enter image description here

And my code, for now, is the following one:

pip install layoutparser[ocr]
import layoutparser as lp 
import matplotlib.pyplot as plt
%matplotlib inline 
import pandas as pd
import numpy as np
import cv2

from google.cloud.vision_v1 import types
import json
import re
from google.cloud import vision
pip show google-cloud-vision

 ocr_agent = lp.GCVAgent.with_credential('mycredebtials.json',
                                   languages = ['es'])
                            

 img = plt.imread(r'D:\pdfDispacher.do_Página_2.jpg', cv2.IMREAD_COLOR) 
 print(img)
 plt.imshow(img)
 res = ocr_agent.detect(img, return_response=True)
 texts  = ocr_agent.gather_text_annotations(res)
 layout = ocr_agent.gather_full_text_annotation(res, agg_level=lp.GCVFeatureType.WORD)
 lp.draw_box(img, layout)
 lp.draw_text(img, layout, font_size=12, with_box_on_text=True,
         text_box_width=1)

What I need is to tell python to get all the columns and rows and save them in CSV format. But I am not able to get this done. I really appreciate it if anyone can help me with the next lines.

0 Answers
Related