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

Add option to show coordinate guidelines when calling draw_text #38

Open ljvmiranda921 opened 3 years ago

ljvmiranda921 commented 3 years ago

Motivation

Hi everyone, thanks for this library! I've been testing it out and it's quite good. I'd like to have a feature request of displaying coordinate guidelines in draw_text to aid in filtering relevant info that I want.

My workflow

I've been using LayoutParser in tandem with Google Cloud Vision. After I get the image, I usually call draw_text. As an example (this is public information of an LGU spend from the Philippines):

image

If I want to get the Current Assets for 2017, I'd still need to do some trial-and-error to filter the exact coordinates for my rectangle. Maybe I'd try 100 first, then 120, etc.

# I still need to trial-and-error the coordinates here. 
# I hope there's a way to better guesstimate this
filtered_assets = layout.filter_by(
    lp.Rectangle(x_1=132, y_1=300, x_2=264, y_2=840)
)

Request: I'd appreciate it if this function also has an option to display coordinate guidelines, so that I can easily "guess-timate" parts I want to filter.

I'm interested to contribute so please let me know which part of the code I can inspect. Thank you!

lolipopshock commented 3 years ago

Thanks for suggesting - that's a great idea!

A simple (but also less elegant) solution you might want to try for now is:

import matplotlib.pyplot as plt 
import numpy as np 
viz = lp.draw_box(...)
plt.imshow(np.array(viz))

It will give you some matplotlib coordinate axes and you could use them as guideline hints.

ljvmiranda921 commented 3 years ago

It works, thank you so much!