Add Line.page and Glyph.line.
This commit is contained in:
parent
f3808df0cd
commit
a373765d3d
1 changed files with 12 additions and 7 deletions
|
|
@ -124,11 +124,11 @@ class Page(PageObject):
|
||||||
line_start = i
|
line_start = i
|
||||||
else:
|
else:
|
||||||
if line_start is not None:
|
if line_start is not None:
|
||||||
yield Line(self.image[line_start:i,:])
|
yield Line(self, self.image[line_start:i,:])
|
||||||
line_start = None
|
line_start = None
|
||||||
prev_line_end = i
|
prev_line_end = i
|
||||||
if line_start is not None:
|
if line_start is not None:
|
||||||
yield Line(self.image[line_start:,:])
|
yield Line(self, self.image[line_start:,:])
|
||||||
|
|
||||||
def _merge_lines(self, lines, min_space=2, min_height=10):
|
def _merge_lines(self, lines, min_space=2, min_height=10):
|
||||||
prev_line = None
|
prev_line = None
|
||||||
|
|
@ -144,7 +144,7 @@ class Page(PageObject):
|
||||||
)
|
)
|
||||||
not_high_enough = prev_line.height < min_height
|
not_high_enough = prev_line.height < min_height
|
||||||
if too_close or not_high_enough:
|
if too_close or not_high_enough:
|
||||||
prev_line = Line(self.image[prev_line.top:line.bottom])
|
prev_line = Line(self, self.image[prev_line.top:line.bottom])
|
||||||
else:
|
else:
|
||||||
yield prev_line
|
yield prev_line
|
||||||
prev_line = line
|
prev_line = line
|
||||||
|
|
@ -153,6 +153,10 @@ class Page(PageObject):
|
||||||
|
|
||||||
|
|
||||||
class Line(PageObject):
|
class Line(PageObject):
|
||||||
|
def __init__(self, page, image):
|
||||||
|
super().__init__(image)
|
||||||
|
self.page = page
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.glyphs)
|
return iter(self.glyphs)
|
||||||
|
|
||||||
|
|
@ -180,7 +184,7 @@ class Line(PageObject):
|
||||||
for (label, blob_slice) in blob_slices
|
for (label, blob_slice) in blob_slices
|
||||||
)
|
)
|
||||||
glyphs = (
|
glyphs = (
|
||||||
Glyph(image, self.baseline - image.bottom)
|
Glyph(self, image, self.baseline - image.bottom)
|
||||||
for image in glyph_images
|
for image in glyph_images
|
||||||
)
|
)
|
||||||
glyphs = sorted(glyphs, key=lambda glyph: (glyph.left, -glyph.bottom))
|
glyphs = sorted(glyphs, key=lambda glyph: (glyph.left, -glyph.bottom))
|
||||||
|
|
@ -214,7 +218,7 @@ class Line(PageObject):
|
||||||
if next_glyph is not None:
|
if next_glyph is not None:
|
||||||
distance = glyph.optical_distance(next_glyph)
|
distance = glyph.optical_distance(next_glyph)
|
||||||
if distance >= min_distance:
|
if distance >= min_distance:
|
||||||
yield Space(self.image.space(glyph.right, self.top, distance, self.height), self.baseline - self.top)
|
yield Space(self, self.image.space(glyph.right, self.top, distance, self.height), self.baseline - self.top)
|
||||||
|
|
||||||
def _extract_blob(self, blob_slice, label, labels):
|
def _extract_blob(self, blob_slice, label, labels):
|
||||||
image = self.image[blob_slice]
|
image = self.image[blob_slice]
|
||||||
|
|
@ -229,9 +233,10 @@ class Line(PageObject):
|
||||||
class Glyph(PageObject):
|
class Glyph(PageObject):
|
||||||
MIN_BODY_HEIGHT = 10
|
MIN_BODY_HEIGHT = 10
|
||||||
|
|
||||||
def __init__(self, image, elevation):
|
def __init__(self, line, image, elevation):
|
||||||
super().__init__(image)
|
super().__init__(image)
|
||||||
self.elevation = elevation
|
self.elevation = elevation
|
||||||
|
self.line = line
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def key(self):
|
def key(self):
|
||||||
|
|
@ -287,7 +292,7 @@ class Glyph(PageObject):
|
||||||
if not diacritics:
|
if not diacritics:
|
||||||
return self
|
return self
|
||||||
diacritic_images = (diacritic.image for diacritic in diacritics)
|
diacritic_images = (diacritic.image for diacritic in diacritics)
|
||||||
return Glyph(combine(self.image, *diacritic_images), self.elevation)
|
return Glyph(self.line, combine(self.image, *diacritic_images), self.elevation)
|
||||||
|
|
||||||
|
|
||||||
class Space(Glyph):
|
class Space(Glyph):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue