Skip to content

Commit

Permalink
modify to use last view instead of first, use new video utils, update…
Browse files Browse the repository at this point in the history
… sdk
  • Loading branch information
kelleyl committed Jul 16, 2024
1 parent 6b8750d commit 49bc382
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
21 changes: 10 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@ def _appmetadata(self):
def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
self.logger.debug("running app")
video_doc: Document = mmif.get_documents_by_type(DocumentTypes.VideoDocument)[0]
input_view: View = mmif.get_views_for_document(video_doc.properties.id)[0]

input_view = mmif.get_views_for_document(video_doc.properties.id)[-1]
new_view: View = mmif.new_view()
self.sign_view(new_view, parameters)

for timeframe in input_view.get_annotations(AnnotationTypes.TimeFrame):
self.logger.debug(timeframe.properties)
representative: AnnotationTypes.TimePoint = (
input_view.get_annotation_by_id(timeframe.get("representatives")[0]))
self.logger.debug("Sampling 1 frame")
# uses SWT v3.0 typo "timePont" instead of "timePoint"
rep_frame = vdh.convert(representative.get("timePont"), "milliseconds",
"frame", vdh.get_framerate(video_doc))
image: np.ndarray = vdh.extract_frames_as_images(video_doc, [rep_frame], as_PIL=False)[0]
representatives = timeframe.get("representatives") if "representatives" in timeframe.properties else None
if representatives:
image = vdh.extract_representative_frame(mmif, timeframe, as_PIL=True)
else:
image = vdh.extract_mid_frame(mmif, timeframe, as_PIL=True)

self.logger.debug("Extracted image")
self.logger.debug("Running OCR")
ocrs = [self.reader.readtext(image, width_ths=0.25)]
ocrs = [self.reader.readtext(np.array(image), width_ths=0.25)]
self.logger.debug(ocrs)
timepoint = representative
timepoint = new_view.new_annotation(AnnotationTypes.TimePoint)
timepoint.add_property('timePoint', timeframe.get("start"))
point_frame = new_view.new_annotation(AnnotationTypes.Alignment)
point_frame.add_property("source", timeframe.id)
point_frame.add_property("target", timepoint.id)
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Make sure clams-python version is explicitly specified, at least the lower bound
clams-python==1.0.9
mmif-python[cv]==1.0.8
clams-python==1.2.6

easyocr==1.7.0
chardet==5.2.0
Expand Down

0 comments on commit 49bc382

Please sign in to comment.