def visualize_corres(points, correspondences, model): points += np.array([1., 0., 0.]).reshape((1, 3)) tree = NN(n_neighbors=1000).fit(points) for idx in [88190, 132644]: #range(100): #idx = np.random.randint(points.shape[0]-1) print('visualizing around point %d' % idx) dists, indices = tree.kneighbors(points[idx, :].reshape((1, 3))) neighbors = indices[0, :] source = points[neighbors, :] #import ipdb; ipdb.set_trace() target = model.verts[correspondences[neighbors], :] edges = vis.getEdges(source, target, 1000, color=np.array([1., 0, 0])) o3d.draw_geometries([ vis.getPointCloud(points), vis.getTriangleMesh(model.verts, model.faces), edges ])
def visualize_smoothness(points, correspondences, model): points += np.array([1., 0., 0.]).reshape((1, 3)) tree = NN(n_neighbors=10).fit(points) dists, indices = tree.kneighbors(points) corres = correspondences[indices] # [n_points, 10] target_points = model.verts[corres, :] # [n_points, 10, 3] mean = target_points.mean(axis=1) # [n_points, 3] dists = target_points - mean[:, np.newaxis, :] # [n_points, 10, 3] dists = np.square(dists).sum(axis=1).sum(axis=1) # [n_points] max_dist = dists.max() min_dist = dists.min() dists = (dists - min_dist) / (max_dist - min_dist) r = np.array([1.0, 0, 0]) b = np.array([0, 0, 1.]) colors = np.array([(r * (di) + b * (1.0 - di)) for di in dists]) pcd = vis.getPointCloud(points) pcd.colors = o3d.utility.Vector3dVector(colors) o3d.draw_geometries([pcd, vis.getTriangleMesh(model.verts, model.faces)])
extrinsics = [] gt_feats = [] gt_correspondences = [] current = 0 used_rotations = [] for i, rotation in enumerate(rotations): transformation = np.eye(4) transformation[:3, :3] = rotation mesh.transform(transformation) depth_image, extrinsic, intrinsic, points3d_i, correspondence, valid_idx = camera.project( mesh.vertices, mesh.triangles) mesh.transform(transformation.T) depth = depth_image[(valid_idx[:, 0], valid_idx[:, 1])] helper.save_to_obj(OBJ.format(scan_id, i), vis.getPointCloud(points3d_i)) gt_correspondence = smpl_corres[correspondence] np.savetxt(CORRES.format(scan_id, i), gt_correspondence, '%d') mat_file = MAT.format(scan_id, i) print('saving to %s' % mat_file) sio.savemat(mat_file, { 'depth': depth, 'points3d': points3d_i, 'valid_pixel_indices': valid_idx, 'correspondence': gt_correspondence, 'mesh_correspondence': correspondence, 'rotation': rotation, 'width': 320, 'height': 240, 'intrinsic': intrinsic, 'extrinsic': extrinsic,