Skip to content

Commit

Permalink
#1 created proper timePoint annotations for bounding boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
snewman-aa committed Jan 11, 2024
1 parent e9a38e2 commit e0a2465
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
sample_frames = config["sampleFrames"]
if timeframe_length < sample_frames:
sample_frames = int(timeframe_length)
sample_ratio = int(timeframe.properties["end"]
- timeframe.properties["start"]) // sample_frames
tf_sample = vdh.sample_frames(timeframe.properties["start"], timeframe.properties["end"],
sample_ratio)
sample_ratio = int(timeframe.get("end") - timeframe.get("start")) // sample_frames
tf_sample = vdh.sample_frames(timeframe.get("start"), timeframe.get("end"), sample_ratio)
images = vdh.extract_frames_as_images(video_doc, tf_sample)
ocrs = []
for image in images:
Expand All @@ -69,14 +67,18 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
self.logger.debug("Confident OCR: " + text)
text_document = new_view.new_textdocument(text)
bbox_annotation = new_view.new_annotation(AnnotationTypes.BoundingBox)
timepoint = new_view.new_annotation(AnnotationTypes.TimePoint)
timepoint.add_property("timePoint", timeframe.properties["start"])
bbox_annotation.add_property("coordinates", coord)
bbox_annotation.add_property("boxType", "text")
# For now, we're gonna use the start time of the timeframe as the timePoint because vdh extract
# midframe doesn't return the frame number
bbox_annotation.add_property("timePoint", timeframe.properties["start"])
align_annotation = new_view.new_annotation(AnnotationTypes.Alignment)
align_annotation.add_property("source", bbox_annotation.id)
align_annotation.add_property("target", text_document.id)
text_align = new_view.new_annotation(AnnotationTypes.Alignment)
text_align.add_property("source", bbox_annotation.id)
text_align.add_property("target", text_document.id)
time_align = new_view.new_annotation(AnnotationTypes.Alignment)
time_align.add_property("source", bbox_annotation.id)
time_align.add_property("target", timepoint.id)

return mmif

Expand Down

0 comments on commit e0a2465

Please sign in to comment.