Closed theiman112860 closed 2 years ago
Hi Shannon, I reinstalled it and this worked perfectly:
import layoutparser as lp
pdf_layout = lp.load_pdf("C:\temp\ConsigneeList\extable.pdf") pdf_layout[0] # the layout for page 0
pdf_layout, pdf_images = lp.load_pdf("C:\temp\ConsigneeList\extable.pdf", load_images=True) lp.draw_box(pdf_images[0], pdf_layout[0])
However, when I use the original code: import layoutparser as lp import cv2 from pdf2image import convert_from_bytes
images = convert_from_bytes(open('C:\\temp\\ConsigneeList\\Doc 4 Distribution List.pdf', 'rb').read())
model = lp.Detectron2LayoutModel(
config_path ='lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config', # In model catalog
label_map = {0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In modellabel_map
extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional
)
#loop through each page
for image in images:
ocr_agent = lp.ocr.TesseractAgent()
image = np.array(image)
layout = model.detect(image)
text_blocks = lp.Layout([b for b in layout if b.type == 'Text']) #loop through each text box on page.
for block in text_blocks:
segment_image = (block
.pad(left=5, right=5, top=5, bottom=5)
.crop_image(image))
text = ocr_agent.detect(segment_image)
block.set(text=text, inplace=True)
for i, txt in enumerate(text_blocks.get_texts()):
my_file = open("OUTPUT FILE PATH/FILENAME.TXT","a+")
my_file.write(txt)
I get the error below.. Any ideas? Thank you!!
Sincerely,
tom
Thanks for the updates @theiman112860 . It seems the error message was not shown in your post -- could you share them again?
Hi Shannon, Sorry about that!! Below is the error output that I am getting. Thank you again!! -th
ValueError Traceback (most recent call last)
Oh I see - this seems to be an issue from the pycoco module. What's the pycoco version on your machine pip show pycocotools
?
Hi Shannon, Its 2.0.2 ..Thank you!
I see -- could you check this https://stackoverflow.com/a/66138833 ?
Hi Shannon, Thank you!! I will check that out!!
I'll have the issue closed as it seems we've found the solution -- feel free to reopen if you have more questions.
Hi Shannon,
Thank you!! I hope that you have a great weekend!!
Sincerely,
Tom
Sent from my iPhone
On Sep 24, 2021, at 3:12 PM, Shannon Shen @.***> wrote:
Closed #77.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
Hi,
Thank you for this awesome program! I successfully installed layout-parser Detectron2 on my windows 10 laptop. When I run the following code:
import layoutparser as lp import cv2 from pdf2image import convert_from_bytes
images = convert_from_bytes(open('C:\temp\ConsigneeList\Doc 4 Distribution List.pdf', 'rb').read())
model = lp.Detectron2LayoutModel( config_path ='lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config', # In model catalog label_map = {0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}, # In model
label_map
extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8] # Optional )loop through each page
for image in images: ocr_agent = lp.ocr.TesseractAgent()
text_blocks = lp.Layout([b for b in layout if b.type == 'Text']) #loop through each text box on page.
for block in text_blocks: segment_image = (block .pad(left=5, right=5, top=5, bottom=5) .crop_image(image)) text = ocr_agent.detect(segment_image) block.set(text=text, inplace=True)
I get the following errors:
AttributeError Traceback (most recent call last)