Ejemplo n.º 1
0
def import_region_json(r,
                       frame_index,
                       video_id,
                       event_id,
                       segment_index=None,
                       frame_id=None):
    dr = Region()
    dr.frame_index = frame_index
    dr.video_id = video_id
    dr.event_id = event_id
    dr.object_name = r['object_name']
    dr.region_type = r.get('region_type', Region.ANNOTATION)
    dr.full_frame = r.get('full_frame', False)
    if segment_index:
        dr.segment_index = segment_index
    if frame_id:
        dr.frame_id = frame_id
    dr.x = r.get('x', 0)
    dr.y = r.get('y', 0)
    dr.w = r.get('w', 0)
    dr.h = r.get('h', 0)
    dr.confidence = r.get('confidence', 0.0)
    if r.get('text', None):
        dr.text = r['text']
    else:
        dr.text = ""
    dr.metadata = r.get('metadata', None)
    return dr
Ejemplo n.º 2
0
 def create_region(self, a):
     da = Region()
     da.video_id = self.video.pk
     da.x = a['x']
     da.y = a['y']
     da.h = a['h']
     da.w = a['w']
     da.vdn_key = a['id']
     if 'text' in a:
         da.text = a['text']
     elif 'metadata_text' in a:
         da.text = a['metadata_text']
     if 'metadata' in a:
         da.metadata = a['metadata']
     elif 'metadata_json' in a:
         da.metadata = a['metadata_json']
     da.materialized = a.get('materialized', False)
     da.png = a.get('png', False)
     da.region_type = a['region_type']
     da.confidence = a['confidence']
     da.object_name = a['object_name']
     da.full_frame = a['full_frame']
     if a.get('event', None):
         da.event_id = self.event_to_pk[a['event']]
     if 'parent_frame_index' in a:
         da.frame_index = a['parent_frame_index']
     else:
         da.frame_index = a['frame_index']
     if 'parent_segment_index' in a:
         da.segment_index = a.get('parent_segment_index', -1)
     else:
         da.segment_index = a.get('segment_index', -1)
     return da
Ejemplo n.º 3
0
def create_region(a,video_obj,vdn_dataset,event_to_pk=None):
    da = Region()
    da.video = video_obj
    da.x = a['x']
    da.y = a['y']
    da.h = a['h']
    da.w = a['w']
    da.vdn_key = a['id']
    if 'text' in a:
        da.text = a['text']
    elif 'metadata_text' in a:
        da.text = a['metadata_text']
    if 'metadata' in a:
        da.metadata = a['metadata']
    elif 'metadata_json' in a:
        da.metadata = a['metadata_json']
    da.materialized = a.get('materialized',False)
    da.png = a.get('png',False)
    da.region_type = a['region_type']
    da.confidence = a['confidence']
    da.object_name = a['object_name']
    da.full_frame = a['full_frame']
    if a.get('event',None):
        da.event_id = event_to_pk[a['event']]
    da.parent_frame_index = a['parent_frame_index']
    da.parent_segment_index = a.get('parent_segment_index',-1)
    if vdn_dataset:
        da.vdn_dataset = vdn_dataset
    return da
Ejemplo n.º 4
0
def import_region(a,video_obj,frame,detection_to_pk,vdn_dataset=None):
    da = Region()
    da.video = video_obj
    da.x = a['x']
    da.y = a['y']
    da.h = a['h']
    da.w = a['w']
    da.vdn_key = a['id']
    da.metadata_text = a['metadata_text']
    da.metadata_json = a['metadata_json']
    da.region_type = a['region_type']
    da.confidence = a['confidence']
    da.object_name = a['object_name']
    da.full_frame = a['full_frame']
    if vdn_dataset:
        da.vdn_dataset = vdn_dataset
    if 'label' in a and a['label'].strip():
        da.label = a['label']
        if vdn_dataset:
            label_object, created = VLabel.objects.get_or_create(label_name=a['label'], source=VLabel.VDN, video=video_obj, vdn_dataset=vdn_dataset)
        else:
            label_object, created = VLabel.objects.get_or_create(label_name=a['label'], source=VLabel.UI, video=video_obj)
        da.label_parent = label_object
    da.frame = frame
    da.save()
    if da.region_type == Region.DETECTION:
        detection_to_pk[a['id']]=da.pk
    return da
Ejemplo n.º 5
0
def import_legacy_detection(d, video_obj, frame, vdn_dataset=None):
    dd = Region()
    dd.region_type = Region.DETECTION
    dd.video = video_obj
    dd.x = d['x']
    dd.y = d['y']
    dd.h = d['h']
    dd.w = d['w']
    dd.frame = frame
    dd.confidence = d['confidence']
    dd.object_name = d['object_name']
    dd.metadata_json = d['metadata']
    if vdn_dataset:
        dd.vdn_dataset = dd.video.vdn_dataset
    dd.vdn_key = d['id']
    dd.save()
    return dd
Ejemplo n.º 6
0
def create_region(a, video_obj, vdn_dataset):
    da = Region()
    da.video = video_obj
    da.x = a['x']
    da.y = a['y']
    da.h = a['h']
    da.w = a['w']
    da.vdn_key = a['id']
    da.metadata_text = a['metadata_text']
    da.metadata_json = a['metadata_json']
    da.region_type = a['region_type']
    da.confidence = a['confidence']
    da.object_name = a['object_name']
    da.full_frame = a['full_frame']
    da.parent_frame_index = a['parent_frame_index']
    if vdn_dataset:
        da.vdn_dataset = vdn_dataset
    return da
Ejemplo n.º 7
0
 def create_region(self, a):
     da = Region()
     da.video_id = self.video.pk
     da.x = a['x']
     da.y = a['y']
     da.h = a['h']
     da.w = a['w']
     da.text = a['text']
     da.metadata = a['metadata']
     da.png = a.get('png', False)
     da.region_type = a['region_type']
     da.confidence = a['confidence']
     da.object_name = a['object_name']
     da.full_frame = a['full_frame']
     da.event_id = self.event_to_pk[a['event']]
     da.frame_index = a['frame_index']
     da.segment_index = a.get('segment_index', -1)
     return da
Ejemplo n.º 8
0
def import_region(a, video_obj, frame, detection_to_pk, vdn_dataset=None):
    da = Region()
    da.video = video_obj
    da.x = a['x']
    da.y = a['y']
    da.h = a['h']
    da.w = a['w']
    da.vdn_key = a['id']
    da.metadata_text = a['metadata_text']
    da.metadata_json = a['metadata_json']
    da.region_type = a['region_type']
    da.confidence = a['confidence']
    da.object_name = a['object_name']
    da.full_frame = a['full_frame']
    if vdn_dataset:
        da.vdn_dataset = vdn_dataset
    da.frame = frame
    da.save()
    if da.region_type == Region.DETECTION:
        detection_to_pk[a['id']] = da.pk
    return da
Ejemplo n.º 9
0
def create_region(a,video_obj,vdn_dataset,event_to_pk=None):
    da = Region()
    da.video = video_obj
    da.x = a['x']
    da.y = a['y']
    da.h = a['h']
    da.w = a['w']
    da.vdn_key = a['id']
    da.metadata_text = a['metadata_text']
    da.metadata_json = a['metadata_json']
    da.materialized = a.get('materialized',False)
    da.png = a.get('png',False)
    da.region_type = a['region_type']
    da.confidence = a['confidence']
    da.object_name = a['object_name']
    da.full_frame = a['full_frame']
    if a.get('event',None):
        da.event_id = event_to_pk[a['event']]
    da.parent_frame_index = a['parent_frame_index']
    da.parent_segment_index = a.get('parent_segment_index',-1)
    if vdn_dataset:
        da.vdn_dataset = vdn_dataset
    return da
Ejemplo n.º 10
0
def import_frame_json(f, frame_index, event_id, video_id):
    regions = []
    df = Frame()
    df.video_id = video_id
    df.event_id = event_id
    df.frame_index = frame_index
    df.name = f['path']
    for r in f.get('regions', []):
        dr = Region()
        dr.frame_index = frame_index
        dr.video_id = video_id
        dr.event_id = event_id
        dr.object_name = r['object_name']
        dr.region_type = r.get('region_type', Region.ANNOTATION)
        dr.full_frame = r.get('full_frame', False)
        dr.x = r.get('x', 0)
        dr.y = r.get('y', 0)
        dr.w = r.get('w', 0)
        dr.h = r.get('h', 0)
        dr.confidence = r.get('confidence', 0.0)
        dr.text = r.get('text', None)
        dr.metadata = r.get('metadata', None)
        regions.append(dr)
    return df, regions
Ejemplo n.º 11
0
def create_region(a, video_obj, vdn_dataset, old_task_to_new=None):
    """
    # TODO: old_task_to_new
    """
    da = Region()
    da.video = video_obj
    da.x = a['x']
    da.y = a['y']
    da.h = a['h']
    da.w = a['w']
    da.vdn_key = a['id']
    da.metadata_text = a['metadata_text']
    da.metadata_json = a['metadata_json']
    da.materialized = a.get('materialized', False)
    da.png = a.get('png', False)
    da.region_type = a['region_type']
    da.confidence = a['confidence']
    da.object_name = a['object_name']
    da.full_frame = a['full_frame']
    da.parent_frame_index = a['parent_frame_index']
    da.parent_segment_index = a.get('parent_segment_index', -1)
    if vdn_dataset:
        da.vdn_dataset = vdn_dataset
    return da