def visualize_helper(box_list): vgrid_spec = VGridSpec( video_meta=video_metadata_intel, vis_format=VideoBlockFormat(imaps=[(str(i), box) for i, box in enumerate(box_list)]), video_endpoint=VIDEO_COLLECTION_BASEURL_INTEL) return VGridWidget(vgrid_spec=vgrid_spec.to_json_compressed())
def find_clips_for_keyword(keyword, use_only_video=False): ism = {} for vm in tqdm(video_metadata): if not vm["annotation_filename"] or (not vm["only_video"] and use_only_video): continue try: h5 = eeghdf.Eeghdf(vm["annotation_filename"]) except: print(vm["annotation_filename"]) os.remove(vm["annotation_filename"]) continue starts = [start / 10**7 for start in h5._annotation_start100ns] texts = h5._annotation_text if not keyword or any(keyword.lower() in text.lower() for text in texts): interval_set = IntervalSet([ Interval( Bounds3D(start, start + 5), # we set the duration { 'spatial_type': SpatialType_Caption(">>" + text + "\n"), 'metadata': {} }) for start, text in zip(starts, texts) ]) ism[vm["id"]] = interval_set print( f"Found {len(ism)} videos with keyword {keyword} in the annotations.") vgrid_spec = VGridSpec(video_meta=video_metadata_wrapper, vis_format=VideoBlockFormat(imaps=[('bboxes', ism)]), video_endpoint='http://localhost:8080') return VGridWidget(vgrid_spec=vgrid_spec.to_json_compressed())
def IntervalSetMapping_to_vgrid(ism, flat=False): video_meta = [] if flat: video_meta_id = 0 ism_final = {} for video_id, intervalSet in ism.items(): video = Video.objects.filter(id=video_id)[0] for i in intervalSet.get_intervals(): ism_final[video_meta_id] = IntervalSet([i]) video_meta.append(VideoMetadata(path=video.path, id=video_meta_id)) video_meta_id += 1 else: for video_id, intervalSet in ism.items(): video = Video.objects.filter(id=video_id)[0] video_meta.append(VideoMetadata(path=video.path, id=video_id)) ism_final = ism vgrid_spec = VGridSpec( video_meta=video_meta, video_endpoint="http://sora.stanford.edu/system_media/", vis_format=VideoBlockFormat([('test', ism_final)]), show_timeline=True) return VGridWidget(vgrid_spec=vgrid_spec.to_json())
) ) pose_metadata[video_meta.id] = IntervalSet(pose_intervals) # In[29]: pose_annotation_files # In[31]: vgrid_spec = VGridSpec( video_meta = metadata_videos, vis_format = VideoBlockFormat(imaps = [ ('pose', IntervalSetMapping(pose_metadata)) ]), video_endpoint = 'http://localhost:8080' ) VGridWidget(vgrid_spec = vgrid_spec.to_json_compressed()) # In[ ]:
ism = IntervalSetMapping({ 0: IntervalSet([ Interval( Bounds3D(0, 10), { 'spatial_type': SpatialType_Temporal(), 'metadata': { 'generic_metadata': Metadata_Generic( 'this will be drawn below the timeline when expanded' ), 'other_generic_metadata': Metadata_Generic({ 'key': 'this object will also be stringified' }) } } ) ]) }) vgrid_spec = VGridSpec( video_meta = video_metadata, vis_format = VideoBlockFormat(imaps = [ ('bboxes', ism) ]) ) # Pass this to your Javascript application somehow json_for_js = vgrid_spec.to_json_compressed()
def vgrid_widget(**kwargs): return VGridWidget(vgrid_spec=VGridSpec( video_endpoint='http://{}/system_media'.format(hostname), frameserver_endpoint='http://{}:7500/fetch'.format(hostname), use_frameserver=True, **kwargs).to_json())