def move_images_and_annotations(old_video_path, new_video_path, keep_frames, change_log):
    file_ext = '.png'

    old_data_dir, tt_split, old_category, old_video_dir = old_video_path.split('/')
    new_data_dir, tt_split, new_category, new_video_dir = new_video_path.split('/')
    annotation_tt_split = 'new_' + tt_split + '_wbox'
    old_annotation_path = '/'.join([old_data_dir, annotation_tt_split, old_category, old_video_dir])
    new_annotation_path = '/'.join([new_data_dir, annotation_tt_split, new_category, new_video_dir])
    save_anno_path = '/'.join([new_data_dir, 'save_fr', annotation_tt_split,
                               new_category, new_video_dir])
    os.makedirs(new_video_path)
    os.makedirs(new_annotation_path)
    os.makedirs(save_anno_path)

    new_frame_idx = 0
    pvn, mvn, sub_n = get_name_parts(old_video_dir)
    if sub_n != 'childless':
        old_video_path = '/'.join([old_data_dir, tt_split, old_category]) + '/' + pvn + '_' + mvn
        old_annotation_path = '/'.join([old_data_dir, annotation_tt_split, old_category]) + '/' + pvn + '_' + mvn
    else:
        sub_n = 0

    span = keep_frames[int(sub_n)]
    for frame in range(int(span[0]), int(span[1])+1):
        old_file = old_video_path + '/' + str(frame).zfill(5) + file_ext
        new_file = new_video_path + '/' + str(new_frame_idx).zfill(5) + file_ext
        os.rename(old_file, new_file)
        append_to_change_log(new_file, old_file, change_log)
        if not os.path.isdir(old_annotation_path):
            append_to_change_log('has no annotations', old_annotation_path, change_log)
            return
        copy_view_mat_files(old_annotation_path, new_annotation_path, change_log)
        move_annotations(old_annotation_path, new_annotation_path, frame, new_frame_idx, change_log)
        new_frame_idx += 1
def move_stable_dir(data_path, change_file_log, new_prefix):
    img_dir_path = (new_prefix + data_path).rsplit('/', maxsplit=1)[0]
    data_dir, an_sub_path, _ = data_path.split('/', maxsplit=2)
    anno_dir_path = new_prefix + data_dir + '/new_' + an_sub_path + '_wbox'

    os.makedirs(img_dir_path)
    os.makedirs(anno_dir_path)
    for stable_file_path in glob.glob(data_path + '/stable*'):
        old_anno = convert_vid_path_to_anno(stable_file_path)
        new_stable_path = new_prefix + stable_file_path
        new_anno = convert_vid_path_to_anno(new_stable_path)
        os.rename(stable_file_path, new_stable_path)
        append_to_change_log(new_stable_path, stable_file_path, change_log_file)
        os.rename(old_anno, new_anno)
        append_to_change_log(new_anno, old_anno, change_log_file)
def move_annotations(old_annotation_path, new_annotation_path, frame, new_frame_idx, change_log):
    annotation_extensions = ['_00.mat', '_00_ge.mat', '_00_fr.mat']
    pov_ext = '_00_fr.mat'
    new_data_dir, annotation_tt_split, new_category, new_video_dir = new_annotation_path.split('/')
    for file_ext in annotation_extensions:
            old_file = old_annotation_path + '/' + str(frame).zfill(5) + file_ext
            if file_ext == pov_ext:
                new_annotation_path = '/'.join([new_data_dir, 'save_fr', annotation_tt_split,
                                                new_category, new_video_dir])
            new_file = new_annotation_path + '/' + str(new_frame_idx).zfill(5) + file_ext
            try:
                os.rename(old_file, new_file)
                append_to_change_log(new_file, old_file, change_log)
            except(ValueError, FileNotFoundError) as e:
                append_to_change_log('doesn\'t exist', old_file, change_log)
示例#4
0
def move_images_and_annotations(old_video_path, new_video_path, keep_frames,
                                change_log):
    file_ext = '.png'

    old_data_dir, tt_split, old_category, old_video_dir = old_video_path.split(
        '/')
    new_data_dir, tt_split, new_category, new_video_dir = new_video_path.split(
        '/')
    annotation_tt_split = 'new_' + tt_split + '_wbox'
    old_annotation_path = '/'.join(
        [old_data_dir, annotation_tt_split, old_category, old_video_dir])
    new_annotation_path = '/'.join(
        [new_data_dir, annotation_tt_split, new_category, new_video_dir])
    save_anno_path = '/'.join([
        new_data_dir, 'save_fr', annotation_tt_split, new_category,
        new_video_dir
    ])
    os.makedirs(new_video_path)
    os.makedirs(new_annotation_path)
    os.makedirs(save_anno_path)

    new_frame_idx = 0
    pvn, mvn, sub_n = get_name_parts(old_video_dir)
    if sub_n != 'childless':
        old_video_path = '/'.join([old_data_dir, tt_split, old_category
                                   ]) + '/' + pvn + '_' + mvn
        old_annotation_path = '/'.join([
            old_data_dir, annotation_tt_split, old_category
        ]) + '/' + pvn + '_' + mvn
    else:
        sub_n = 0

    span = keep_frames[int(sub_n)]
    for frame in range(int(span[0]), int(span[1]) + 1):
        old_file = old_video_path + '/' + str(frame).zfill(5) + file_ext
        new_file = new_video_path + '/' + str(new_frame_idx).zfill(
            5) + file_ext
        os.rename(old_file, new_file)
        append_to_change_log(new_file, old_file, change_log)
        if not os.path.isdir(old_annotation_path):
            append_to_change_log('has no annotations', old_annotation_path,
                                 change_log)
            return
        copy_view_mat_files(old_annotation_path, new_annotation_path,
                            change_log)
        move_annotations(old_annotation_path, new_annotation_path, frame,
                         new_frame_idx, change_log)
        new_frame_idx += 1
示例#5
0
def move_stable_dir(data_path, change_file_log, new_prefix):
    img_dir_path = (new_prefix + data_path).rsplit('/', maxsplit=1)[0]
    data_dir, an_sub_path, _ = data_path.split('/', maxsplit=2)
    anno_dir_path = new_prefix + data_dir + '/new_' + an_sub_path + '_wbox'

    os.makedirs(img_dir_path)
    os.makedirs(anno_dir_path)
    for stable_file_path in glob.glob(data_path + '/stable*'):
        old_anno = convert_vid_path_to_anno(stable_file_path)
        new_stable_path = new_prefix + stable_file_path
        new_anno = convert_vid_path_to_anno(new_stable_path)
        os.rename(stable_file_path, new_stable_path)
        append_to_change_log(new_stable_path, stable_file_path,
                             change_log_file)
        os.rename(old_anno, new_anno)
        append_to_change_log(new_anno, old_anno, change_log_file)
示例#6
0
def move_annotations(old_annotation_path, new_annotation_path, frame,
                     new_frame_idx, change_log):
    annotation_extensions = ['_00.mat', '_00_ge.mat', '_00_fr.mat']
    pov_ext = '_00_fr.mat'
    new_data_dir, annotation_tt_split, new_category, new_video_dir = new_annotation_path.split(
        '/')
    for file_ext in annotation_extensions:
        old_file = old_annotation_path + '/' + str(frame).zfill(5) + file_ext
        if file_ext == pov_ext:
            new_annotation_path = '/'.join([
                new_data_dir, 'save_fr', annotation_tt_split, new_category,
                new_video_dir
            ])
        new_file = new_annotation_path + '/' + str(new_frame_idx).zfill(
            5) + file_ext
        try:
            os.rename(old_file, new_file)
            append_to_change_log(new_file, old_file, change_log)
        except (ValueError, FileNotFoundError) as e:
            append_to_change_log('doesn\'t exist', old_file, change_log)
示例#7
0
def test_train_split_three_cats(replacement_dir, new_prefix, change_log):
    random.seed(15)
    for rep_dir in glob.glob(replacement_dir + '/*'):
        for mov in glob.glob(rep_dir + '/*'):
            anno_dir = mov.replace('prediction_videos_3_categories',
                                   'new_prediction_videos_3_categories_wbox')
            if random.randint(1, 3) < 3:
                new_vid_path = mov.replace('3_categories', 'final_train')
                new_anno_path = anno_dir.replace('3_categories', 'final_train')

            else:
                new_vid_path = mov.replace('3_categories', 'final_test')
                new_anno_path = anno_dir.replace('3_categories', 'final_test')
            os.makedirs(new_vid_path)
            os.makedirs(new_anno_path)
            try:
                os.rename(mov, new_vid_path)
                os.rename(anno_dir, new_anno_path)
            except FileNotFoundError:
                with open(change_log, 'a') as log:
                    log.write(mov + ' annotations not found \n')
            append_to_change_log(new_vid_path, mov, change_log)
            append_to_change_log(new_anno_path, anno_dir, change_log)
def test_train_split_three_cats(replacement_dir, new_prefix, change_log):
    random.seed(15)
    for rep_dir in glob.glob(replacement_dir+'/*'):
        for mov in glob.glob(rep_dir + '/*'):
            anno_dir = mov.replace('prediction_videos_3_categories',
                                   'new_prediction_videos_3_categories_wbox')
            if random.randint(1, 3) < 3:
                new_vid_path = mov.replace('3_categories', 'final_train')
                new_anno_path = anno_dir.replace('3_categories', 'final_train')

            else:
                new_vid_path = mov.replace('3_categories', 'final_test')
                new_anno_path =anno_dir.replace('3_categories', 'final_test')
            os.makedirs(new_vid_path)
            os.makedirs(new_anno_path)
            try:
                os.rename(mov, new_vid_path)
                os.rename(anno_dir, new_anno_path)
            except FileNotFoundError:
                with open(change_log, 'a') as log:
                    log.write(mov + ' annotations not found \n')
            append_to_change_log(new_vid_path, mov, change_log)
            append_to_change_log(new_anno_path, anno_dir, change_log)
def move_confirmed(old_path, new_path, change_log):
    old_data_dir, tt_split, old_category, old_video_dir = old_path.split('/')
    new_data_dir, tt_split, new_category, new_video_dir = new_path.split('/')
    annotation_tt_split = 'new_' + tt_split + '_wbox'

    old_annotation_path = '/'.join([old_data_dir, annotation_tt_split, old_category, old_video_dir])
    new_annotation_path = '/'.join([new_data_dir, annotation_tt_split, new_category, new_video_dir])

    move_confirmed_pov_files(old_path, new_path, change_log)
    os.makedirs(new_path)
    os.makedirs(new_annotation_path)

    os.rename(old_path, new_path)
    if not os.path.isdir(old_annotation_path):
        append_to_change_log('has no annotations', old_annotation_path, change_log)
        return
    os.rename(old_annotation_path, new_annotation_path)

    append_to_change_log(new_path + ' without cuts', old_path, change_log)
    append_to_change_log(new_annotation_path + ' without cuts', old_annotation_path, change_log)
示例#10
0
def move_confirmed(old_path, new_path, change_log):
    old_data_dir, tt_split, old_category, old_video_dir = old_path.split('/')
    new_data_dir, tt_split, new_category, new_video_dir = new_path.split('/')
    annotation_tt_split = 'new_' + tt_split + '_wbox'

    old_annotation_path = '/'.join(
        [old_data_dir, annotation_tt_split, old_category, old_video_dir])
    new_annotation_path = '/'.join(
        [new_data_dir, annotation_tt_split, new_category, new_video_dir])

    move_confirmed_pov_files(old_path, new_path, change_log)
    os.makedirs(new_path)
    os.makedirs(new_annotation_path)

    os.rename(old_path, new_path)
    if not os.path.isdir(old_annotation_path):
        append_to_change_log('has no annotations', old_annotation_path,
                             change_log)
        return
    os.rename(old_annotation_path, new_annotation_path)

    append_to_change_log(new_path + ' without cuts', old_path, change_log)
    append_to_change_log(new_annotation_path + ' without cuts',
                         old_annotation_path, change_log)