def cli(filename, segmented=False, steps=1, scale=1.): """Render a 3D model for an estimated body fit. Provide the image (!!) filename.""" model = { 'neutral': _load_model( _os.path.join(_os.path.dirname(__file__), '..', 'models', '3D', 'basicModel_neutral_lbs_10_207_0_v1.0.0.pkl')) } fileending = filename[-4:] pkl_fname = filename.replace(fileending, '.pkl') if not _path.exists(pkl_fname): pkl_fname = filename[:-10] + '_body.pkl' if not _path.exists(pkl_fname): pkl_fname = filename + '_body.pkl' _LOGGER.info("Rendering 3D model for image %s and parameters %s...", filename, pkl_fname) assert _os.path.exists(pkl_fname), ( 'Stored body fit does not exist for {}: {}!'.format( filename, pkl_fname)) image = cv2.imread(filename) with open(pkl_fname) as f: cam = pickle.load(f) renderings = render(model['neutral'], image, cam, steps, segmented, scale) for ridx, rim in enumerate(renderings): if segmented: out_fname = filename + '_body_segmented_%d.png' % (ridx) else: out_fname = filename + '_body_%d.png' % (ridx) cv2.imwrite(out_fname, rim)
# 11 Left wrist 20 # 12 Neck - # 13 Head top fake # guess the focal length _FLENGTH_GUESS = 5000. #2500. # initial value for the camera translation (in meters) _T_GUESS = _np.array([0, 0, 20.]) # number of model shape coefficients to optimize _N_BETAS = 10 _MOD_PATH = _os.path.abspath(_os.path.dirname(__file__)) # Models: _MODEL_NEUTRAL_FNAME = _os.path.join( _MOD_PATH, '..', 'models', '3D', 'basicModel_neutral_lbs_10_207_0_v1.0.0.pkl') _MODEL_NEUTRAL = _load_model(_MODEL_NEUTRAL_FNAME) # Torso joint IDs (used for estimating camera position). _CID_TORSO = [ landmarks_91.rhip, landmarks_91.lhip, landmarks_91.rshoulder, landmarks_91.lshoulder ] # Head position correction. _HEAD_CORR_FNAME = _os.path.join(_MOD_PATH, '..', 'models', '3D', 'head_vid_heva.pkl') with open(_HEAD_CORR_FNAME, 'r') as f: _HEAD_REGR = _pickle.load(f) _REGRESSORS_FNAME = _os.path.join(_MOD_PATH, '..', 'models', '3D', 'regressors_locked_normalized_hybrid.npz') _REGRESSORS = _np.load(_REGRESSORS_FNAME) # Project the regressors on the first 10 beta dimensions. _REGP = dict()
# Models: # Models: current_dir = _os.path.dirname(_os.path.abspath(__file__)) parent_dir = _os.path.abspath(_os.path.join(current_dir, _os.pardir)) _MODEL_NEUTRAL_FNAME = _os.path.join(parent_dir, 'models', '3D', 'neutral_smpl_with_cocoplus_reg.pkl') _MODEL_MALE_FNAME = _os.path.join(parent_dir, 'models', '3D', 'basicmodel_m_lbs_10_207_0_v1.0.0.pkl') _MODEL_FEME_FNAME = _os.path.join(parent_dir, 'models', '3D', 'basicModel_f_lbs_10_207_0_v1.0.0.pkl') _MODEL_N = _load_model(_MODEL_NEUTRAL_FNAME) _MODEL_M = _load_model(_MODEL_MALE_FNAME) _MODEL_F = _load_model(_MODEL_FEME_FNAME) _MODEL_VT = _os.path.join(parent_dir, 'models', 'basicModel_vt.npy') _MODEL_FT = _os.path.join(parent_dir, 'models', 'basicModel_ft.npy') _MODEL_VT_FT_OBJ = _os.path.join(parent_dir, 'models', 'mapeamento_impaint_2.obj') def Template_tex(): #mesh.vt,mesh.ft = Template_tex() vt = np.load(_MODEL_VT)