Add optional line text field to coordinate format (helps with text output format in some languages/corner cases)
This commit is contained in:
@@ -110,6 +110,7 @@ class Line:
|
|||||||
"""Represents a single line of text, composed of words."""
|
"""Represents a single line of text, composed of words."""
|
||||||
bounding_box: BoundingBox
|
bounding_box: BoundingBox
|
||||||
words: List[Word] = field(default_factory=list)
|
words: List[Word] = field(default_factory=list)
|
||||||
|
text: Optional[str] = None
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Paragraph:
|
class Paragraph:
|
||||||
@@ -567,6 +568,7 @@ class Bing:
|
|||||||
words.append(word)
|
words.append(word)
|
||||||
|
|
||||||
line = Line(
|
line = Line(
|
||||||
|
text=l.get('text', ''),
|
||||||
bounding_box=self._quad_to_center_bbox(l['boundingBox']),
|
bounding_box=self._quad_to_center_bbox(l['boundingBox']),
|
||||||
words=words
|
words=words
|
||||||
)
|
)
|
||||||
@@ -840,6 +842,7 @@ class AppleLiveText:
|
|||||||
|
|
||||||
l_bbox = l.quad().boundingBox()
|
l_bbox = l.quad().boundingBox()
|
||||||
line = Line(
|
line = Line(
|
||||||
|
text=l.string(),
|
||||||
bounding_box=BoundingBox(
|
bounding_box=BoundingBox(
|
||||||
width=l_bbox.size.width,
|
width=l_bbox.size.width,
|
||||||
height=l_bbox.size.height,
|
height=l_bbox.size.height,
|
||||||
@@ -996,6 +999,7 @@ class OneOCR:
|
|||||||
words.append(word)
|
words.append(word)
|
||||||
|
|
||||||
line = Line(
|
line = Line(
|
||||||
|
text=l.get('text', ''),
|
||||||
bounding_box=self._pixel_quad_to_center_bbox(l['bounding_rect'], img_width, img_height),
|
bounding_box=self._pixel_quad_to_center_bbox(l['bounding_rect'], img_width, img_height),
|
||||||
words=words
|
words=words
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -729,6 +729,9 @@ class OutputResult:
|
|||||||
full_text_parts = []
|
full_text_parts = []
|
||||||
for p in result_data.paragraphs:
|
for p in result_data.paragraphs:
|
||||||
for l in p.lines:
|
for l in p.lines:
|
||||||
|
if l.text != None:
|
||||||
|
full_text_parts.append(l.text)
|
||||||
|
else:
|
||||||
for w in l.words:
|
for w in l.words:
|
||||||
full_text_parts.append(w.text)
|
full_text_parts.append(w.text)
|
||||||
if w.separator != None:
|
if w.separator != None:
|
||||||
|
|||||||
Reference in New Issue
Block a user