def draw_face_edges(self, keypoints, part_list, transform_A, size, add_dist_map, outsize=(256,256)): w, h = size w_o, h_o = outsize edge_len = 3 # interpolate 3 keypoints to form a curve when drawing edges # edge map for face region from keypoints im_edges = np.zeros((h_o, w_o), np.uint8) # edge map for all edges dist_tensor = 0 e = 1 for edge_list in part_list: for edge in edge_list: im_edge = np.zeros((h_o, w_o), np.uint8) # edge map for the current edge for i in range(0, max(1, len(edge)-1), edge_len-1): # divide a long edge into multiple small edges when drawing sub_edge = edge[i:i+edge_len] x = keypoints[sub_edge, 0].astype(np.float32)/ w * w_o y = keypoints[sub_edge, 1].astype(np.float32)/ h * h_o curve_x, curve_y = interpPoints(x.astype(np.int), y.astype(np.int)) # interp keypoints to get the curve shape drawEdge(im_edges, curve_x, curve_y, bw=0) if add_dist_map: drawEdge(im_edge, curve_x, curve_y, bw=0) if add_dist_map: # add distance transform map on each facial part im_edge_tr = Image.fromarray(im_edge).resize(self.osize, Image.NEAREST) im_edge_tr = np.asarray(im_edge_tr) im_dist = cv2.distanceTransform(255-im_edge_tr, cv2.DIST_L1, 3) im_dist = np.clip((im_dist / 3), 0, 255).astype(np.uint8) im_dist = Image.fromarray(im_dist) tensor_cropped = transform_A(im_dist) dist_tensor = tensor_cropped if e == 1 else torch.cat([dist_tensor, tensor_cropped]) e += 1 return im_edges, dist_tensor
def draw_face_edges(self, keypoints, part_list, transform_A, size, add_dist_map): w, h = size edge_len = 3 # interpolate 3 keypoints to form a curve when drawing edges # edge map for face region from keypoints im_edges = np.zeros((h, w), np.uint8) # edge map for all edges dist_tensor = 0 e = 1 for edge_list in part_list: for edge in edge_list: im_edge = np.zeros((h, w), np.uint8) # edge map for the current edge for i in range(0, max(1, len(edge)-1), edge_len-1): # divide a long edge into multiple small edges when drawing sub_edge = edge[i:i+edge_len] x = keypoints[sub_edge, 0] y = keypoints[sub_edge, 1] curve_x, curve_y = interpPoints(x, y) # interp keypoints to get the curve shape drawEdge(im_edges, curve_x, curve_y) if add_dist_map: drawEdge(im_edge, curve_x, curve_y) if add_dist_map: # add distance transform map on each facial part im_dist = cv2.distanceTransform(255-im_edge, cv2.DIST_L1, 3) im_dist = np.clip((im_dist / 3), 0, 255).astype(np.uint8) im_dist = Image.fromarray(im_dist) tensor_cropped = transform_A(self.crop(im_dist)) dist_tensor = tensor_cropped if e == 1 else torch.cat([dist_tensor, tensor_cropped]) e += 1 return im_edges, dist_tensor
def get_face_image(self, keypoints, transform_L, size, bw): w, h = size edge_len = 3 # interpolate 3 keypoints to form a curve when drawing edges # edge map for face region from keypoints im_edges = np.zeros((h, w), np.uint8) # edge map for all edges for edge_list in self.part_list: for edge in edge_list: for i in range(0, max(1, len(edge)-1), edge_len-1): # divide a long edge into multiple small edges when drawing sub_edge = edge[i:i+edge_len] x = keypoints[sub_edge, 0] y = keypoints[sub_edge, 1] curve_x, curve_y = interpPoints(x, y) # interp keypoints to get the curve shape drawEdge(im_edges, curve_x, curve_y, bw=1) input_tensor = transform_L(Image.fromarray(im_edges)) return input_tensor