def show_results(img, results, dataset): img = np.minimum(img, 1500) img = (img - img.min()) / (img.max() - img.min()) img = np.uint8(img*255) img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) img_show = util.draw_pose(dataset, img, results) return img_show
def show_pose(dataset_model, dataset_image, base_dir, outputs, list_file, save_dir, is_flip, gif): if list_file is None: names = util.load_names(dataset_image) else: with open(list_file) as f: names = [line.strip() for line in f] assert len(names) == outputs.shape[0] for idx, (name, pose) in enumerate(zip(names, outputs)): img = util.load_image(dataset_image, os.path.join(base_dir, name), is_flip=is_flip) img = img.astype(np.float32) img = (img - img.min()) / (img.max() - img.min()) * 255 img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) img = util.draw_pose(dataset_model, img, pose) cv2.imshow('result', img / 255) if save_dir is not None: cv2.imwrite(os.path.join(save_dir, '{:>06d}.png'.format(idx)), img) ch = cv2.waitKey(25) if ch == ord('q'): break if gif and save_dir is not None: os.system( 'convert -loop 0 -page +0+0 -delay 25 {0}/*.png {0}/output.gif'. format(save_dir))
def show_results(img, results, cropped_image, dataset): img = np.minimum(img, 1500) img = (img - img.min()) / (img.max() - img.min()) img = np.uint8(img * 255) # draw cropped image img[:96, :96] = (cropped_image + 1) * 255 / 2 img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) cv2.rectangle(img, (0, 0), (96, 96), (255, 0, 0), thickness=2) img_show = util.draw_pose(dataset, img, results) return img_show
### this segment is only for validation ############################################################################################## lbls = util.load_labels(dataset, phase) ### load test/train data names = util.load_names(dataset, phase) centers = util.load_centers(dataset, phase).astype(float) for idx, name in enumerate(names): if idx % 1000 == 0: lbl = np.asarray(np.reshape(lbls[idx].split(), (21, 3)), dtype=np.float32) lbl, skel_camcoords = util.world2pixel(lbl, dataset) img = util.load_image(dataset, os.path.join(root_dir, name)) img /= 1160 img *= 255 points = centers[idx] img = util.draw_pose(dataset, img, lbl, 3, (255, 0, 0), points) cv2.imwrite( root_dir + 'samples/depth/' + phase + '_' + str(idx) + '.png', img) ############################################################################################## ############################# Normalize Labels ################################# ### Make sure centers are calculated using get_centers.py before running this ### Also make sure you are working with original non normalized 3D joint coordinates not the normalized ones. ### After running this segment you should rename the original and give this new file the original's name so that it becomes the labels file used moving forward ################################################################################ lbls = util.load_labels(dataset, phase) # load original test/train data centers = util.load_centers(dataset, phase).astype(float) fx, fy, ux, uy = util.get_param(dataset) out_file = root_dir + 'labels/fpad_' + phase + '_label_nm.txt' lbls = np.asarray([s.split() for s in lbls], dtype=np.float32)
centers = util.load_centers(dataset,phase).astype(float) fx, fy, ux, uy = util.get_param(dataset) lbls = [s.split() for s in lbls] lbls = np.reshape(np.asarray(lbls, dtype=np.float32),(-1,63)) lbls = util.transform_pose(dataset, lbls, centers, 150, fx, fy) # norm to 2D pixel centers = np.reshape(centers,(-1,3)) for idx, name in enumerate(names): if idx%1000 == 0: lbl = util.pixel2world(lbls[idx], dataset) # pixel to 3D world lbl, skel_camcoords = util.world2pixel(lbl, dataset) # back to 2d pixel from 3D world img = util.load_image(dataset, os.path.join(root_dir, name)) points = centers[idx] img = util.draw_pose(dataset, img, lbl, 5, (0,255,0), points) cv2.imwrite(root_dir+'samples/rgb/from_norm/'+phase+'_'+str(idx)+'.png', img) plt = util.plot_joints(dataset, os.path.join(root_dir, name), lbl, skel_camcoords, points) plt.savefig(root_dir+'samples/rgb/from_norm/'+phase+'_'+str(idx)+'_plot.png') ############################################################################################################################################# ############################ Resize RGB images to match input size ################################# ### Crop the RGB images using the crop size in mm and store in cropped directory ##################################################################################################### cropped = 'cropped/' names = util.load_names(dataset,phase) centers = util.load_centers(dataset,phase).astype(float) centers = np.reshape(centers, (-1,3))
cords_d = np.reshape(cords_d, (-1, 3)) cords_3d = util.pixel2world(cords_d, 'fpad') cords_c, skel_camcoords = util.world2pixel(cords_3d, 'fpac') cords_3d = np.reshape(cords_3d, (480, 640, -1)) img_rgbd = np.zeros((img.shape[0], img.shape[1], 4)) cords_c = np.reshape(cords_c, (480, 640, 3)) img_rgbd = image_loops.color_map(img, cimg, img_rgbd, cords_c) img_rgbd = np.asarray(img_rgbd) img = np.asarray(img_rgbd[:, :, :3]).copy() pred, skel_camcoords = util.world2pixel(preds[idx], 'fpad') label, skel_camcoords = util.world2pixel(lbls[idx], 'fpad') points = centers[idx] img = util.draw_pose('fpad', img, pred, 3, (0, 0, 255)) img = cv2.resize(img, (320, 240)) cv2.imwrite(root_dir + 'samples/rgbd/predictions/' + str(idx) + '.png', img) video_name = root_dir + 'samples/rgbd/predictions/videos/' + action + '.avi' image_folder = root_dir + 'samples/rgbd/predictions/' images = [img for img in os.listdir(image_folder) if img.endswith(".png")] images = [img.replace('.png', '') for img in images] images.sort(key=float) images = [img + '.png' for img in images] frame = cv2.imread(os.path.join(image_folder, images[0])) height, width, layers = frame.shape
x1 = train_d[i, :, :, :] if dataset in ('rgbd', 'fpac'): x1 = np.swapaxes(x1, 2, 0) x1 += 1 x1 *= 255 x1 /= 2 y1 = train_j[i, :] y1 = y1.reshape(J, 3) y1 = (y1 + 1) / 2 * 96 if dataset == 'fpad': x1 = x1.reshape(96, 96, 1) img = cv2.cvtColor(x1, cv2.COLOR_GRAY2RGB) else: img = x1[:, :, :3].copy() if dataset == 'rgbd': img = util.draw_pose('fpad', img, y1, 2, (0, 0, 255)) else: img = util.draw_pose(dataset, img, y1, 2, (0, 0, 255)) img = cv2.resize(img, (200, 200)) cv2.imwrite( root_dir + 'trial/' + dataset + '/train_' + str(i) + '.png', img) for i in range(test_d.shape[0]): if i % 1000 == 0: x2 = test_d[i, :, :, :] if dataset in ('rgbd', 'fpac'): x2 = np.swapaxes(x2, 2, 0) x2 += 1 x2 *= 255 x2 /= 2 y2 = test_j[i, :]