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):