Layout-Parser / layout-parser

A Unified Toolkit for Deep Learning Based Document Image Analysis
https://layout-parser.github.io/
Apache License 2.0
4.78k stars 459 forks source link

table parse using tesseract #35

Open ziodos opened 3 years ago

ziodos commented 3 years ago

Hi, first I would like to thank you for this amazing project , I am asking if you could provide some details about how can I run the ocr table notebook using tesseract ocr , in your example you are using google vision api, thank you

farazk86 commented 3 years ago

To get the layout using Tesseract use the following:

ocr_agent = lp.TesseractAgent(languages='eng')
res = ocr_agent.detect(image, return_response=True)
layout  = ocr_agent.gather_data(res, agg_level=lp.TesseractFeatureType.WORD) 

and the rest of the tutorial is same

mattdeeperinsights commented 2 years ago

Update I have fixed the error you can see at the bottom!

Original message

Hi there, thanks for the update, this doesn't work for me however:

I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/p6/v7jprs6526gcc3dqw6rhjj8w0000gn/T/ipykernel_20263/3263327315.py in <module>
----> 1 ocr_agent = lp.TesseractAgent(languages='eng')

/usr/local/lib/python3.9/site-packages/layoutparser/file_utils.py in __getattr__(self, name)
    224             value = getattr(module, name)
    225         else:
--> 226             raise AttributeError(f"module {self.__name__} has no attribute {name}")
    227 
    228         setattr(self, name, value)

AttributeError: module layoutparser has no attribute TesseractAgent

It looks like there is some code for the TesseractAgent but I just can't work out how to import it.

Any suggestions?

Solution

I first needed to import the ocr tool kit and the models:

!pip3 install "layoutparser[ocr]"
!pip3 install "layoutparser[layoutmodels]"