39 lines
1022 B
Python
39 lines
1022 B
Python
import numpy as np
|
|
from scipy import interpolate
|
|
|
|
def resample_by_nsteps(feat, nsteps_tgt):
|
|
"""
|
|
feat, (nframes, ... ) (with source_fps)
|
|
"""
|
|
|
|
nsteps_src = feat.shape[0]
|
|
data_idx = np.arange(0, nsteps_src, 1)
|
|
samp_idx = np.arange(0, nsteps_src-1, (nsteps_src - 1) / nsteps_tgt)
|
|
# print(f"data_idx = {list(data_idx)} \nsmap_idx = {list(samp_idx)}")
|
|
|
|
# sample function
|
|
func = interpolate.interp1d(data_idx, y=feat, axis=0)
|
|
data_interpolate = func(samp_idx)
|
|
|
|
return data_interpolate
|
|
|
|
|
|
def convert_fps(data, source_fps = 30, target_fps=25):
|
|
"""
|
|
data, (nframes, ... ) (with source_fps)
|
|
"""
|
|
|
|
nsize = data.shape[0]
|
|
data_idx = np.arange(0, nsize, 1)
|
|
samp_idx = np.arange(0, nsize-1, 1.0*source_fps/target_fps)
|
|
|
|
func = interpolate.interp1d(data_idx, data=data, axis=0)
|
|
data_interpolate = func(samp_idx)
|
|
|
|
if source_fps < target_fps:
|
|
data_interpolate = np.concatenate([data_interpolate, data[-1:]])
|
|
|
|
return data_interpolate
|
|
|
|
|
|
# def |