|
''' |
|
@Desc: From camera.pkl and reconstructed_poses.hdf5, get the camera.npz and smpl_rec.npz |
|
Example: python xxx.py --root /home/zjp/DeepDynamicFashion/Data_depth/xinyu_a --save_root /home/zjp/DeepDynamicFashion/Data_depth/xinyu_a --gender female |
|
''' |
|
import h5py |
|
import pickle |
|
import numpy as np |
|
import torch |
|
import os |
|
import os.path as osp |
|
import cv2 |
|
from tqdm import tqdm |
|
from glob import glob |
|
import shutil |
|
import argparse |
|
parser = argparse.ArgumentParser(description='neu video body rec') |
|
parser.add_argument('--root',default=None,metavar='M', |
|
help='data root') |
|
parser.add_argument('--sid',default=0,type=int,metavar='IDs', |
|
help='start frame index') |
|
parser.add_argument('--save_root',default=None,metavar='M', |
|
help='save data root') |
|
parser.add_argument('--gender', type=str, default='female') |
|
args = parser.parse_args() |
|
|
|
root=args.root |
|
sid=args.sid |
|
gender=args.gender |
|
save_root=args.save_root |
|
os.makedirs(save_root,exist_ok=True) |
|
|
|
|
|
|
|
|
|
|
|
img_files = sorted(glob(os.path.join(root,'imgs/*.jpg'))) |
|
frame_num = len(img_files) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with h5py.File(osp.join(root,'reconstructed_poses.hdf5'),'r') as ff: |
|
shape=ff['betas'][:].reshape(10) |
|
poses=ff['pose'][:].reshape(-1,24,3)[sid:,:,:] |
|
trans=ff['trans'][:].reshape(-1,3)[sid:,:] |
|
assert(poses.shape[0]>=frame_num-sid and trans.shape[0]>=frame_num-sid) |
|
np.savez(osp.join(save_root,'smpl_rec.npz'),poses=poses,shape=shape,trans=trans,gender=gender) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(osp.join(root,'camera.pkl'),'rb') as ff: |
|
cam_data=pickle.load(ff,encoding='latin1') |
|
ps=cam_data['camera_c'] |
|
fs=cam_data['camera_f'] |
|
trans=cam_data['camera_t'] |
|
rt=cam_data['camera_rt'] |
|
assert(np.linalg.norm(rt)<0.0001) |
|
H=cam_data['height'] |
|
W=cam_data['width'] |
|
|
|
quat=np.array([np.cos(np.pi/2.),0.,0.,np.sin(np.pi/2.)]) |
|
T=trans |
|
fx=fs[0] |
|
fy=fs[1] |
|
cx=ps[0] |
|
cy=ps[1] |
|
print(fx,fy,cx,cy,quat,T) |
|
|
|
np.savez(osp.join(save_root,'camera.npz'),fx=fx,fy=fy,cx=cx,cy=cy,quat=quat,T=T) |
|
|
|
|
|
|
|
|
|
|
|
|