def animation_for_char(fig, ax, sample_data, rate=30):
    if ax is None:
        return None

    # process the data, rescale time length...
    timelen_array = sample_data[:, -1]
    nframes_array = timelen_array * rate * 3
    motion_data = []
    motionframenum_array = []
    for strk_idx in range(len(nframes_array)):
        strk_data = np.reshape(sample_data[strk_idx][0:-1], (2, -1)).T
        # print len(strk_data), int(nframes_array[strk_idx])
        resample_strk_data = utils.interp_traj(strk_data, int(nframes_array[strk_idx]))
        motion_data.append(resample_strk_data)
        motionframenum_array.append(len(resample_strk_data))
    motionframenum_array = np.cumsum(motionframenum_array)
    motion_data_stacked = np.vstack(motion_data)
    # print sample_data
    # print timelen_array
    # print motion_data

    tol_nframes = motionframenum_array[-1]
    frame_data_array = []
    last_frame_data = [[]]
    for frame_idx in range(tol_nframes):
        new_start_pnt = np.any(motionframenum_array == frame_idx)
        if new_start_pnt:
            last_frame_data.append([])
        # insert to the active stroke from the last frame data
        last_frame_data[len(last_frame_data) - 1].append(motion_data_stacked[frame_idx, :])
        frame_data_array.append(copy.deepcopy(last_frame_data))

    def init_animation():
        global line
        for strk_data in frame_data_array[0]:
            strk_data_array = np.array(strk_data)
            line, = ax.plot(strk_data_array[:, 0], -strk_data_array[:, 1], "b", linewidth=4.0)
            ax.hold(True)
        ax.set_xlim([-1.5, 1.5])
        ax.set_ylim([-1.5, 1.5])

    def animate(nframe):
        for strk_data in frame_data_array[nframe]:
            strk_data_array = np.array(strk_data)
            line, = ax.plot(strk_data_array[:, 0], -strk_data_array[:, 1], "b", linewidth=4.0)
            ax.hold(True)
        ax.set_xlim([-1.5, 1.5])
        ax.set_ylim([-1.5, 1.5])
        ax.hold(False)

    anim = animation.FuncAnimation(fig, animate, init_func=init_animation, frames=tol_nframes)

    return anim
def resample_data_to_2d_array_list(sample_data, rate=30):
    """
    resample the data to a 2d array list...
    """
    timelen_array = sample_data[:, -1]
    nframes_array = timelen_array * rate * 3
    motion_data = []
    for strk_idx in range(len(nframes_array)):
        strk_data = np.reshape(sample_data[strk_idx][0:-1], (2, -1)).T
        # print len(strk_data), int(nframes_array[strk_idx])
        resample_strk_data = utils.interp_traj(strk_data, int(nframes_array[strk_idx]))
        motion_data.append(resample_strk_data)

    return motion_data
Example #3
0
def resample_data_to_2d_array_list(sample_data, rate=30):
    '''
    resample the data to a 2d array list...
    '''
    timelen_array = sample_data[:, -1]
    nframes_array = timelen_array * rate * 3
    motion_data = []
    for strk_idx in range(len(nframes_array)):
        strk_data = np.reshape(sample_data[strk_idx][0:-1], (2, -1)).T
        # print len(strk_data), int(nframes_array[strk_idx])
        resample_strk_data = utils.interp_traj(strk_data,
                                               int(nframes_array[strk_idx]))
        motion_data.append(resample_strk_data)

    return motion_data
Example #4
0
def animation_for_char(fig, ax, sample_data, rate=30):
    if ax is None:
        return None

    #process the data, rescale time length...
    timelen_array = sample_data[:, -1]
    nframes_array = timelen_array * rate * 3
    motion_data = []
    motionframenum_array = []
    for strk_idx in range(len(nframes_array)):
        strk_data = np.reshape(sample_data[strk_idx][0:-1], (2, -1)).T
        # print len(strk_data), int(nframes_array[strk_idx])
        resample_strk_data = utils.interp_traj(strk_data,
                                               int(nframes_array[strk_idx]))
        motion_data.append(resample_strk_data)
        motionframenum_array.append(len(resample_strk_data))
    motionframenum_array = np.cumsum(motionframenum_array)
    motion_data_stacked = np.vstack(motion_data)
    # print sample_data
    # print timelen_array
    # print motion_data

    tol_nframes = motionframenum_array[-1]
    frame_data_array = []
    last_frame_data = [[]]
    for frame_idx in range(tol_nframes):
        new_start_pnt = np.any(motionframenum_array == frame_idx)
        if new_start_pnt:
            last_frame_data.append([])
        #insert to the active stroke from the last frame data
        last_frame_data[len(last_frame_data) - 1].append(
            motion_data_stacked[frame_idx, :])
        frame_data_array.append(copy.deepcopy(last_frame_data))

    def init_animation():
        global line
        for strk_data in frame_data_array[0]:
            strk_data_array = np.array(strk_data)
            line, = ax.plot(strk_data_array[:, 0],
                            -strk_data_array[:, 1],
                            'b',
                            linewidth=4.0)
            ax.hold(True)
        ax.set_xlim([-1.5, 1.5])
        ax.set_ylim([-1.5, 1.5])

    def animate(nframe):
        for strk_data in frame_data_array[nframe]:
            strk_data_array = np.array(strk_data)
            line, = ax.plot(strk_data_array[:, 0],
                            -strk_data_array[:, 1],
                            'b',
                            linewidth=4.0)
            ax.hold(True)
        ax.set_xlim([-1.5, 1.5])
        ax.set_ylim([-1.5, 1.5])
        ax.hold(False)

    anim = animation.FuncAnimation(fig,
                                   animate,
                                   init_func=init_animation,
                                   frames=tol_nframes)

    return anim