Skip to content

Commit

Permalink
Individual bounding box annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
snewman-aa committed Aug 23, 2023
1 parent df76f89 commit e9a38e2
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
image: np.ndarray = vdh.extract_mid_frame(mmif, timeframe, as_PIL=False)
self.logger.debug("Extracted image")
self.logger.debug("Running OCR")
ocrs = [self.reader.readtext(image)]
ocrs = [self.reader.readtext(image, width_ths=0.25)]
self.logger.debug(ocrs)
else:
self.logger.debug(f"Sampling {config['sampleFrames']} frames")
Expand All @@ -61,25 +61,22 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
images = vdh.extract_frames_as_images(video_doc, tf_sample)
ocrs = []
for image in images:
ocrs.append(self.reader.readtext(image))
ocrs.append(self.reader.readtext(image, width_ths=0.25))

full_text = ""
scores = []
for ocr in ocrs:
for coord, text, score in ocr:
if score > 0.4:
full_text += text + " "
scores.append(score)

self.logger.debug("Confident OCR: " + full_text)

# add OCR output to text document
text_document = new_view.new_textdocument(full_text)
# text_document.add_property("confidence", score)
align_annotation = new_view.new_annotation(AnnotationTypes.Alignment)
align_annotation.add_property("source", timeframe.id)
align_annotation.add_property("target", text_document.id)
pass
self.logger.debug("Confident OCR: " + text)
text_document = new_view.new_textdocument(text)
bbox_annotation = new_view.new_annotation(AnnotationTypes.BoundingBox)
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)

return mmif

Expand Down

0 comments on commit e9a38e2

Please sign in to comment.