Пример #1
0
from vo_core.track_preprocess import convert_rel_vo
''' Configuration ------------------------------------------------------------------------------------------------------
'''
base_dir = '/home/ziqianb/Desktop/intel'

seq_name = 'apartment'

frames = FrameSeqData(os.path.join(base_dir, seq_name, 'seq.json'))
refer_T = frames.get_Tcw(frames.frames[0])
convert_rel_vo(frames, refer_T)

in_intrinsic = np.asarray([525.0, 525.0, 320.0, 240.0], dtype=np.float32)
in_K = cam_opt.K_from_intrinsic(in_intrinsic)
''' Scripts ------------------------------------------------------------------------------------------------------------
'''
plot_frames_seq_2d(frames, show_view_direction=True)
plt.show()

vis = Visualizer()
frame_idx = 0
x_2d = cam_opt.x_2d_coords(int(in_intrinsic[3] * 2), int(in_intrinsic[2] * 2))
# x_2d = cam_opt.x_2d_coords(480, 640)


def keyPressEvent(obj, event):
    global frame_idx
    global refer_T
    key = obj.GetKeySym()
    if key == 'Right':
        # vis.clear_frame_poses()
        # if frame_idx > 30:
        # If the subset is less than setting, ignore
        if len(sub_frames) >= frames_per_subseq_num:
            sub_seq_list.append(sub_frames)

    print('sel: %d', len(sub_seq_list))
    return sub_seq_list


if __name__ == '__main__':
    ori_seq_json_path = '/home/luwei/mnt/Tango/ziqianb/SUN3D/seq.json'
    ori_seq = FrameSeqData(ori_seq_json_path)
    sub_seq_list = rand_sel_subseq_sun3d(ori_seq, trans_thres_range=0.2, rot_thres=15.0, max_subseq_num=20, frames_per_subseq_num=5)

    # out_sub_seq_list = []
    # for seq in sub_seq_list:
    #     frame_instances = copy.deepcopy(seq.frames)
    #     for frame in frame_instances:
    #         frame['extrinsic_Tcw'] = frame['extrinsic_Tcw'].ravel().tolist()
    #         frame['camera_intrinsic'] = frame['camera_intrinsic'].ravel().tolist()
    #     out_sub_seq_list.append(frame_instances)
    # with open('/home/luwei/mnt/Tango/ziqianb/SUN3D/seq_list.json', 'w') as out_json_file:
    #     json.dump(out_sub_seq_list, out_json_file, indent=2)

    # Show 2D seq
    plt.figure()
    ax = plt.gca()
    plot_frames_seq_2d(ori_seq, ax, legend='all')
    for sub_seq in sub_seq_list:
        plot_frames_seq_2d(sub_seq, ax)
    plt.show()
# Toggle to show 2D seq map instead of image sequences
show_2d_path = True

# Load the original frame and random sample subset
ori_seq = frame_seq_data.FrameSeqData(ori_seq_json_path)
# sub_seq_list = seq_data.random_sel_frames.rand_sel_subseq(scene_frames=ori_seq,
#                                                           trans_thres=0.15,
#                                                           frames_per_subseq_num=10,
#                                                           frames_range=(0.00, 0.8),
#                                                           max_subseq_num=30,
#                                                           interval_skip_frames=2)
''' Scripts  -----------------------------------------------------------------------------------------------------------
'''
if show_2d_path:
    plt.figure()
    ax = plt.gca()
    plt_seq.plot_frames_seq_2d(ori_seq, ax, legend='all')
    # for sub_seq in sub_seq_list:
    #     plt_seq.plot_frames_seq_2d(sub_seq, ax, point_style='x-')
    plt.show()
else:
    pass
    # for seq in sub_seq_list:
    #     img_list = []
    #     for frame in seq.frames:
    #         cur_name = frame['file_name']
    #         cur_frame_idx = frame['id']
    #         cur_img = cv2.imread(os.path.join(base_dir, cur_name)).astype(np.float32) / 255.0
    #         img_list.append({'img': cur_img, "title": cur_frame_idx})
    #     show_multiple_img(img_list)
show_2d_path = True

# Load the original frame and random sample subset
ori_seq = frame_seq_data.FrameSeqData(ori_seq_json_path)
sub_seq_list = seq_data.random_sel_frames.rand_sel_subseq_sun3d(
    scene_frames=ori_seq,
    trans_thres_range=0.15,
    frames_per_subseq_num=10,
    frames_range=(0.00, 0.8),
    max_subseq_num=30,
    interval_thres=2)
''' Scripts  -----------------------------------------------------------------------------------------------------------
'''
if show_2d_path:
    plt.figure()
    ax = plt.gca()
    plt_seq.plot_frames_seq_2d(ori_seq, ax, legend='all')
    for sub_seq in sub_seq_list:
        plt_seq.plot_frames_seq_2d(sub_seq, ax, point_style='x-')
    plt.show()
else:
    for seq in sub_seq_list:
        img_list = []
        for frame in seq.frames:
            cur_name = frame['file_name']
            cur_frame_idx = frame['id']
            cur_img = cv2.imread(os.path.join(base_dir, cur_name)).astype(
                np.float32) / 255.0
            img_list.append({'img': cur_img, "title": cur_frame_idx})
        show_multiple_img(img_list)