def main(): label_map = cv2.imread('./data/labelmap_filled.png', -1) label_inner = getinnerpts('./data/labelmap_filled.png') mask_inner = getinnerpts('./data/img_input_mask.png') input_mask = cv2.imread('./data/img_input_mask.png') disp = input_mask.copy() # warp_label_map(label_inner, label_map, mask_inner, head_label, disp) # warp_label_map(label_inner, label_map, mask_inner, torso_label, disp) # warp_label_map(label_inner, label_map, mask_inner, left_down_label, disp) # warp_label_map(label_inner, label_map, mask_inner, right_up_label, disp) # warp_label_map(label_inner, label_map, mask_inner, right_down_label, disp) # warp_label_map(label_inner, label_map, mask_inner, left_up_label, disp) # # cv2.imwrite('./data/labelmap_warp_coarse.png', disp) labelmapfilling(mask_inner, './data/labelmap_warp_coarse.png', './data/labelmap_warp_filled.png')
def warpnfill(mask_input, mask_smpl, map_smpl, warp_coarse, warp_filled, ifoutlier=False): contour_input = pc.getContour(mask_input, mode=0) contour_smpl = pc.getContour(mask_smpl, mode=0) phi = pc.dpBoundarymatch(contour_input, contour_smpl, 32) # to check the contour point match # pc.dispCorres([224, 224], contour_input, contour_smpl, phi) # exit() inner_smpl = wp.getinnerpts(mask_smpl) weights = wp.calweights(contour_smpl, phi, inner_smpl) wp.warpmap(mask_input, map_smpl, warp_coarse, contour_input, inner_smpl, weights) inner_input = wp.getinnerpts(mask_input) input_contour_all = pc.getContour(mask_input, mode=1) hf.holefilling(warp_coarse, warp_filled, inner_input, input_contour_all, mask_input_front, outlier=ifoutlier)
def getlabelarea(initial_map_path, smpl_map_path, part_label): initial_map = cv2.imread(initial_map_path, -1) smpl_map = cv2.imread(smpl_map_path, -1) initial_inner = wp.getinnerpts(initial_map_path) smpl_inner = wp.getinnerpts(smpl_map_path) initial_output = np.zeros((224, 224), dtype=np.uint8) smpl_output = np.zeros((224, 224), dtype=np.uint8) for i in range(initial_inner.shape[0]): x, y = initial_inner[i, :] if (initial_map[y, x] == part_label).all() == True: initial_output[y, x] = 255 for i in range(smpl_inner.shape[0]): x, y = smpl_inner[i, :] if (smpl_map[y, x] == part_label).all() == True: smpl_output[y, x] = 255 return initial_output, smpl_output
def initialcontours(front_path, back_path): front = cv2.imread(front_path, -1) inner_pts1 = getinnerpts(front_path) inner_pts1 = inner_pts1.tolist() if len(front.shape) == 3: front = cv2.cvtColor(front, cv2.COLOR_BGR2GRAY) contours1, hierarchy = cv2.findContours(front, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours1 = np.array(contours1) back = cv2.imread(back_path, -1) inner_pts2 = getinnerpts(back_path) inner_pts2 = inner_pts2.tolist() if len(back.shape) == 3: back = cv2.cvtColor(back, cv2.COLOR_BGR2GRAY) contours2, hierarchy = cv2.findContours(back, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours2 = np.array(contours2) return contours1, contours2, inner_pts1, inner_pts2
def main(): # left_up_initial, left_up_smpl = getlabelarea('./data/labelmap_warp_filled.png', './data/labelmap_filled.png', # left_up_label) # left_up_map = label_match(left_up_initial, left_up_smpl) # # left_down_initial, left_down_smpl = getlabelarea('./data/labelmap_warp_filled.png', './data/labelmap_filled.png', # left_down_label) # # left_down_map = label_match(left_down_initial, left_down_smpl) # # torso_initial, torso_smpl = getlabelarea('./data/labelmap_warp_filled.png', './data/labelmap_filled.png', # torso_label) # torso_map = label_match(torso_initial, torso_smpl) # # occlusion_pairs = pixel_occlusion('./data/labelmap_warp_filled.png', left_up_initial, left_up_map, torso_map, # left_down_map, './data/img_depth.png') # occlusion_mask_init = cv2.imread('./data/labelmap_warp_filled.png', -1) # for i in range(occlusion_pairs.shape[0]): # x1, y1, x2, y2 = occlusion_pairs[i, :] # occlusion_mask_init[y1, x1] = [255, 255, 255] # occlusion_mask_init[y2, x2] = [255, 255, 255] # # cv2.imwrite('./data/occlusion_mask_init.png', occlusion_mask_init) # occlusion_mask_dilate = dilate_occlusion_mask('./data/occlusion_mask_init.png') # cv2.imwrite('./data/occlusion_mask_dilate.png', occlusion_mask_dilate) mask_O = [] occlusion_mask_dilate = cv2.imread('./data/occlusion_mask_dilate.png', -1) for i in range(occlusion_mask_dilate.shape[0]): for j in range(occlusion_mask_dilate.shape[1]): if (occlusion_mask_dilate[i, j] == [255, 255, 255]).all() == True: mask_O.append([j, i]) mask_O = np.array(mask_O) label_inner = wp.getinnerpts('./data/labelmap_warp_filled.png') contours = conbine_main_parts('./data/labelmap_warp_filled.png', label_inner, left_up_label) contour_points, start, end = find_occlusion_endpoints(contours, mask_O) print(start, end)
def main(): mask_smpl = './data/img_smpl_mask.png' pred_vert = './savetxt/pred_vertices.txt' head = './smpl_seg_raw/refined/head.txt' torso = './smpl_seg_raw/refined/torso.txt' left_up = './smpl_seg_raw/refined/left_arm_hand.txt' left_down = './smpl_seg_raw/refined/left_leg_foot.txt' right_up = './smpl_seg_raw/refined/right_arm_hand.txt' right_down = './smpl_seg_raw/refined/right_leg_foot.txt' head_index = np.loadtxt(head, dtype=np.int) torso_index = np.loadtxt(torso, dtype=np.int) left_up_index = np.loadtxt(left_up, dtype=np.int) left_down_index = np.loadtxt(left_down, dtype=np.int) right_up_index = np.loadtxt(right_up, dtype=np.int) right_down_index = np.loadtxt(right_down, dtype=np.int) inner_pts = getinnerpts(mask_smpl) rect1 = cv2.minAreaRect(inner_pts) pred_v = np.loadtxt(pred_vert, dtype=np.float32) pred_v2d = pred_v[:, :2] + 1 # to eliminate negative values rect2 = cv2.minAreaRect(pred_v2d) a = rect1[1][0] / rect2[1][0] b = rect1[1][1] / rect2[1][1] c = rect1[0][0] - rect2[0][0] d = rect1[0][1] - rect2[0][1] print(a, b, c, d) pred_v2d[:, 0] = (pred_v2d[:, 0] - rect2[0][0]) * a + c pred_v2d[:, 1] = (pred_v2d[:, 1] - rect2[0][1]) * b + d pred_v2d = np.array(pred_v2d, dtype=np.int) mask = cv2.imread(mask_smpl) # mask = np.zeros((mask.shape[0], mask.shape[1])) # for i in range(pred_v2d.shape[0]): # x, y = pred_v2d[i, :] # cv2.circle(mask, (x, y), 1, (255, 0, 0)) for i in range(head_index.shape[0]): x, y = pred_v2d[head_index[i], :] cv2.circle(mask, (x, y), 1, (193, 182, 255)) for i in range(torso_index.shape[0]): x, y = pred_v2d[torso_index[i], :] cv2.circle(mask, (x, y), 1, (144, 128, 112)) for i in range(left_down_index.shape[0]): x, y = pred_v2d[left_down_index[i], :] cv2.circle(mask, (x, y), 1, (0, 255, 127)) for i in range(right_up_index.shape[0]): x, y = pred_v2d[right_up_index[i], :] cv2.circle(mask, (x, y), 1, (0, 69, 255)) for i in range(right_down_index.shape[0]): x, y = pred_v2d[right_down_index[i], :] cv2.circle(mask, (x, y), 1, (205, 250, 255)) for i in range(left_up_index.shape[0]): x, y = pred_v2d[left_up_index[i], :] cv2.circle(mask, (x, y), 1, (139, 139, 0)) cv2.imshow('label', mask) cv2.waitKey(0) cv2.destroyAllWindows() cv2.imwrite('./data/labelmap_coarse.png', mask) labelmapfilling(inner_pts, './data/labelmap_coarse.png', './data/labelmap_filled.png')