Layout Parser: lp.draw_box not working in for loop

410 views Asked by At

I am trying to visualize pages after passing through layout parser using lp.draw_box. It works fine for a single image, but if I run through a for loop and try for each image at once from a set of images, it doesn't print anything. Could someone please help me here? THanks

Code:

from pdf2image import convert_from_path, convert_from_bytes
import cv2, time

start = time.time()
images = convert_from_path(f"/content/neft-system-faq.pdf")
page_layout_map = {}
for idx, image in enumerate(images):
    image.save('out.png', 'PNG')
    image = cv2.imread("out.png")
    image = image[..., ::-1]
    layout = model.detect(image)
    lp.draw_box(image, layout,None,show_element_id=True)
    text_blocks = lp.Layout([b for b in layout])    
    print(text_blocks)    
    block_test = get_coordinates(text_blocks)
    result_arr = layout_map_processor(block_test)    
    page_layout_map[idx] = result_arr
   

print(time.time()-start)

1

There are 1 answers

0
Mayar Hanafy On

try this it worked with me:

viz=lp.draw_box(image,layout,box_width=4)
display(viz)