def sample_texture(img, pts, ref, tm): """returns a texture vector""" img = normalize(img, get_aabb(pts)) mask = get_mask(ref, img.shape[:2]) verts = get_vertices(ref) warp = tm.warp_triangles(img, pts[verts], ref[verts]) return warp[mask].ravel()
def get_data_matrix(imgs, lmks, ref): ref = ref.reshape((ref.size//2, 2)).astype('int32') mask = get_mask(ref, (640, 480)) # FIXME hardcoded image size verts = get_vertices(ref) tm = TextureMapper(480, 640) # ditto n_samples = lmks.shape[1] n_pixels = mask.sum() * 3 G = np.empty((n_pixels, n_samples)) for i in range(n_samples): src = lmks[:,i].reshape(ref.shape) img = normalize(next(imgs), get_aabb(src)) warp = tm.warp_triangles(img, src[verts], ref[verts]) G[:,i] = warp[mask].ravel() return G
def get_data_matrix(imgs, lmks, ref): ref = ref.reshape((ref.size//2, 2)).astype('int32') mask = get_mask(ref, (640, 480)) # FIXME hardcoded image size verts = get_vertices(ref) tm = TextureMapper(480, 640) # ditto n_samples = lmks.shape[1] n_pixels = mask.sum() * 3 G = np.empty((n_pixels, n_samples)) for i in xrange(n_samples): src = lmks[:,i].reshape(ref.shape) img = normalize(next(imgs), get_aabb(src)) warp = tm.warp_triangles(img, src[verts], ref[verts]) G[:,i] = warp[mask].ravel() return G
def calc_params(self, img, lmk, ref, warp_triangles): ref = ref.reshape((ref.size//2, 2)).astype('int32') src = lmk.reshape(ref.shape) img = normalize(img, get_aabb(src)) mask = get_mask(ref, img.shape[:2]) verts = get_vertices(ref) warp = warp_triangles(img, src[verts], ref[verts]) t = warp[mask].ravel() - self.mean p = self.model.T.dot(t) # clamp c = 3 for i in range(len(self.variance)): v = c * np.sqrt(self.variance[i]) if abs(p[i]) > v: p[i] = v if p[i] > 0 else -v return p
def calc_params(self, img, lmk, ref, warp_triangles): ref = ref.reshape((ref.size//2, 2)).astype('int32') src = lmk.reshape(ref.shape) img = normalize(img, get_aabb(src)) mask = get_mask(ref, img.shape[:2]) verts = get_vertices(ref) warp = warp_triangles(img, src[verts], ref[verts]) t = warp[mask].ravel() - self.mean p = self.model.T.dot(t) # clamp c = 3 for i in xrange(len(self.variance)): v = c * np.sqrt(self.variance[i]) if abs(p[i]) > v: p[i] = v if p[i] > 0 else -v return p
def draw_texture(img, texture, points): texture = texture.round().reshape((texture.size // 3, 3)) mask = get_mask(points, img.shape[:2]) img[mask] = texture return img
def draw_texture(img, texture, points): texture = texture.round().reshape((texture.size//3, 3)) mask = get_mask(points, img.shape[:2]) img[mask] = texture return img