def fit_pose(frame, last_smpl, frustum, nohands, viz_rn): if nohands: faces = faces_no_hands(frame.smpl.f) else: faces = frame.smpl.f dst_type = cv2.cv.CV_DIST_L2 if cv2.__version__[0] == '2' else cv2.DIST_L2 dist_i = cv2.distanceTransform(np.uint8(frame.mask * 255), dst_type, 5) - 1 dist_i[dist_i < 0] = 0 dist_i[dist_i > 50] = 50 dist_o = cv2.distanceTransform(255 - np.uint8(frame.mask * 255), dst_type, 5) dist_o[dist_o > 50] = 50 rn_m = ColoredRenderer(camera=frame.camera, v=frame.smpl, f=faces, vc=np.ones_like(frame.smpl), frustum=frustum, bgcolor=0, num_channels=1) E = { 'mask': gaussian_pyramid(rn_m * dist_o * 100. + (1 - rn_m) * dist_i, n_levels=4, normalization='size') * 80., '2dpose': GMOf(frame.pose_obj, 100), 'prior': frame.pose_prior_obj * 4., 'sp': frame.collision_obj * 1e3, } if last_smpl is not None: E['last_pose'] = GMOf(frame.smpl.pose - last_smpl.pose, 0.05) * 50. E['last_trans'] = GMOf(frame.smpl.trans - last_smpl.trans, 0.05) * 50. if nohands: x0 = [ frame.smpl.pose[range(21) + range(27, 30) + range(36, 60)], frame.smpl.trans ] else: x0 = [ frame.smpl.pose[range(21) + range(27, 30) + range(36, 72)], frame.smpl.trans ] ch.minimize(E, x0, method='dogleg', options={ 'e_3': .01, }, callback=get_cb(viz_rn, frame))
def ray_objective(f, sigma, base_smpl, camera, vis_rn_b, vis_rn_m): base_smpl.pose[:] = f.pose camera.t[:] = f.trans f.v_ids, f.rays_u = unpose_and_select_rays(f.rays, f.Vi, base_smpl, vis_rn_b, vis_rn_m) f.verts = base_smpl.v_shaped_personal[f.v_ids] f.dist = distance_function(f.rays_u, f.verts) return GMOf(f.dist, sigma)
def reinit_frame(frame, null_pose, nohands, viz_rn): mylog("# reinit_frame") if (np.sum(frame.pose_obj.r ** 2) > 625 or np.sum(frame.pose_prior_obj.r ** 2) > 75)\ and np.sum(frame.keypoints[[0, 2, 5, 8, 11], 2]) > 3.: log.info('Tracking error too large. Re-init frame...') x0 = [frame.smpl.pose[:3], frame.smpl.trans] frame.smpl.pose[3:] = null_pose if frame.keypoints[2, 0] > frame.keypoints[5, 0]: frame.smpl.pose[0] = 0 frame.smpl.pose[2] = np.pi E = { 'init_pose': frame.pose_obj[[0, 2, 5, 8, 11]], } ch.minimize(E, x0, method='dogleg', options={ 'e_3': .1, }, callback=get_cb(viz_rn, frame)) E = { 'pose': GMOf(frame.pose_obj, 100), 'prior': frame.pose_prior_obj * 8., } x0 = [frame.smpl.trans] if nohands: # x0.append(frame.smpl.pose[range(21) + range(27, 30) + range(36, 60)]) x0.append(frame.smpl.pose[list(range(21)) + list(range(27, 30)) + list(range(36, 60))]) else: # x0.append(frame.smpl.pose[range(21) + range(27, 30) + range(36, 72)]) x0.append(frame.smpl.pose[list(range(21)) + list(range(27, 30)) + list(range(36, 72))]) ch.minimize(E, x0, method='dogleg', options={ 'e_3': .01, }, callback=get_cb(viz_rn, frame))
def ray_face(f, sigma, base_smpl, camera, face_ids): camera.t[:] = f.trans f.v_ids, f.rays_u, w_idx = select_rays(f.face_rays, f.Vi, base_smpl, face_ids) f.verts = base_smpl.v_shaped_personal[f.v_ids] f.dist = distance_function(f.rays_u, f.verts) w = f.face_landmark[:, -1][w_idx].reshape(-1, 1) x = GMOf(f.dist, sigma) fina = x * w return fina # paper2