@@ -30,49 +30,37 @@ def _annotate(self, mmif: Union[str, dict, Mmif], **parameters) -> Mmif:
30
30
video_doc : Document = mmif .get_documents_by_type (DocumentTypes .VideoDocument )[0 ]
31
31
input_view : View = mmif .get_views_for_document (video_doc .properties .id )[0 ]
32
32
33
- config = self .get_configuration (** parameters )
34
33
new_view : View = mmif .new_view ()
35
34
self .sign_view (new_view , parameters )
36
35
37
36
for timeframe in input_view .get_annotations (AnnotationTypes .TimeFrame ):
38
37
self .logger .debug (timeframe .properties )
39
- # get images from time frame
40
- if config ["sampleFrames" ] == 1 :
41
- self .logger .debug ("Sampling 1 frame" )
42
- image : np .ndarray = vdh .extract_mid_frame (mmif , timeframe , as_PIL = False )
43
- self .logger .debug ("Extracted image" )
44
- self .logger .debug ("Running OCR" )
45
- ocrs = [self .reader .readtext (image , width_ths = 0.25 )]
46
- self .logger .debug (ocrs )
47
- else :
48
- self .logger .debug (f"Sampling { config ['sampleFrames' ]} frames" )
49
- timeframe_length = int (timeframe .properties ["end" ] - timeframe .properties ["start" ])
50
- sample_frames = config ["sampleFrames" ]
51
- if timeframe_length < sample_frames :
52
- sample_frames = int (timeframe_length )
53
- sample_ratio = int (timeframe .get ("end" ) - timeframe .get ("start" )) // sample_frames
54
- tf_sample = vdh .sample_frames (timeframe .get ("start" ), timeframe .get ("end" ), sample_ratio )
55
- images = vdh .extract_frames_as_images (video_doc , tf_sample )
56
- ocrs = []
57
- for image in images :
58
- ocrs .append (self .reader .readtext (image , width_ths = 0.25 ))
59
-
38
+ self .logger .debug ("Sampling 1 frame" )
39
+ # Samples midframe of timeframe until SWT outputs TimePoints
40
+ image : np .ndarray = vdh .extract_mid_frame (mmif , timeframe , as_PIL = False )
41
+ self .logger .debug ("Extracted image" )
42
+ self .logger .debug ("Running OCR" )
43
+ ocrs = [self .reader .readtext (image , width_ths = 0.25 )]
44
+ self .logger .debug (ocrs )
45
+ timepoint = new_view .new_annotation (AnnotationTypes .TimePoint )
46
+ timepoint .add_property ("timePoint" , vdh .get_mid_framenum (mmif , timeframe ))
47
+ point_frame = new_view .new_annotation (AnnotationTypes .Alignment )
48
+ point_frame .add_property ("source" , timeframe .id )
49
+ point_frame .add_property ("target" , timepoint .id )
60
50
for ocr in ocrs :
61
51
for coord , text , score in ocr :
62
52
if score > 0.4 :
63
53
self .logger .debug ("Confident OCR: " + text )
64
54
text_document = new_view .new_textdocument (text )
65
55
bbox_annotation = new_view .new_annotation (AnnotationTypes .BoundingBox )
66
- timepoint = new_view .new_annotation (AnnotationTypes .TimePoint )
67
- timepoint .add_property ("timePoint" , timeframe .properties ["start" ])
68
56
bbox_annotation .add_property ("coordinates" , coord )
69
57
bbox_annotation .add_property ("boxType" , "text" )
70
- text_align = new_view .new_annotation (AnnotationTypes .Alignment )
71
- text_align .add_property ("source" , bbox_annotation .id )
72
- text_align .add_property ("target" , text_document .id )
73
- time_align = new_view .new_annotation (AnnotationTypes .Alignment )
74
- time_align .add_property ("source" , bbox_annotation .id )
75
- time_align .add_property ("target" , timepoint .id )
58
+ time_bbox = new_view .new_annotation (AnnotationTypes .Alignment )
59
+ time_bbox .add_property ("source" , timepoint .id )
60
+ time_bbox .add_property ("target" , bbox_annotation .id )
61
+ bbox_text = new_view .new_annotation (AnnotationTypes .Alignment )
62
+ bbox_text .add_property ("source" , bbox_annotation .id )
63
+ bbox_text .add_property ("target" , text_document .id )
76
64
77
65
return mmif
78
66
0 commit comments