From c5d04ff6aa906f57f92b35184b9253fde3866637 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Mon, 25 Aug 2014 16:22:01 +0200 Subject: [PATCH] Add Image.fits() and PageObject.fits(). --- pixelocr/image.py | 10 ++++++++++ pixelocr/page.py | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/pixelocr/image.py b/pixelocr/image.py index 427ae08..fe1d9bd 100644 --- a/pixelocr/image.py +++ b/pixelocr/image.py @@ -212,6 +212,16 @@ class Image(object): data = np.ma.masked_array(self.data, mask3, fill_value=255).filled() return Image(data, self.x, self.y) + def fits(self, left, top, right, bottom): + """Return True if the image fits into the given bounding box.""" + + return ( + self.top >= top + and self.left >= left + and self.right <= right + and self.bottom <= bottom + ) + def _iter_lines(self, min_space): def iter_lines(): line_start = None diff --git a/pixelocr/page.py b/pixelocr/page.py index dd6df57..e5cda0e 100644 --- a/pixelocr/page.py +++ b/pixelocr/page.py @@ -80,6 +80,11 @@ class PageObject(object): def ycenter(self): return (self.bottom - self.top) / 2 + def fits(self, left, top, right, bottom): + """Return True if the glyph fits into the given bounding box.""" + + return self.image.fits(left, top, right, bottom) + class Page(PageObject): def __iter__(self):