Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paddle ocr refined #42

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

import cache

"""
Helper function for showing debug information

def some_function(x):
from utils import app # import inside function
app.logger.debug(x)
"""

class OCRFrame():
"""
Expand Down Expand Up @@ -64,10 +71,10 @@ def add_bounding_box(self, anno, mmif):
else:
for alignment_anns in mmif.get_alignments(AnnotationTypes.BoundingBox, AnnotationTypes.TimePoint).values():
for alignment_ann in alignment_anns:
if alignment_ann.get('source') == anno.id:
if alignment_ann.get('source') == anno.long_id:
timepoint_anno = mmif[alignment_ann.get('target')]
break
elif alignment_ann.get('target') == anno.id:
elif alignment_ann.get('target') == anno.long_id:
timepoint_anno = mmif[alignment_ann.get('source')]
break
if timepoint_anno:
Expand All @@ -93,8 +100,7 @@ def add_timeframe(self, anno, mmif):
start_id, end_id = anno.properties.get(
"targets")[0], anno.properties.get("targets")[-1]
anno_parent = mmif.get_view_by_id(anno.parent)
start_anno, end_anno = anno_parent.get_annotation_by_id(
start_id), anno_parent.get_annotation_by_id(end_id)
start_anno, end_anno = anno_parent.get_annotation_by_id(start_id), anno_parent.get_annotation_by_id(end_id)
start = convert_timepoint(mmif, start_anno, "frames")
end = convert_timepoint(mmif, end_anno, "frames")
start_secs = convert_timepoint(mmif, start_anno, "seconds")
Expand Down Expand Up @@ -163,6 +169,8 @@ def get_ocr_frames(view, mmif):

# Account for alignment in either direction
frame = OCRFrame(source, mmif)
if target.at_type == DocumentTypes.TextDocument:
frame.add_timepoint(source, mmif, skip_if_view_has_frames=False)
frame.update(target, mmif)

i = frame.frame_num if frame.frame_num is not None else frame.range
Expand Down
Loading