layout-parser icon indicating copy to clipboard operation
layout-parser copied to clipboard

Add option to show coordinate guidelines when calling draw_text

Open ljvmiranda921 opened this issue 3 years ago • 2 comments

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!

ljvmiranda921 avatar Apr 27 '21 01:04 ljvmiranda921

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.

lolipopshock avatar Apr 27 '21 05:04 lolipopshock

It works, thank you so much!

ljvmiranda921 avatar Apr 28 '21 08:04 ljvmiranda921