def interpolate(sxyzs,sprobs,qxyzs,ratio=1.0/(2*0.15*0.15)): nidxs=libPointUtil.findNeighborInAnotherCPU(sxyzs,qxyzs,8) nidxs_lens=np.asarray([len(idxs) for idxs in nidxs],dtype=np.int32) nidxs_bgs=compute_nidxs_bgs(nidxs_lens) nidxs=np.concatenate(nidxs,axis=0) qprobs = libPointUtil.interpolateProbsGPU(sxyzs, qxyzs, sprobs, nidxs, nidxs_lens, nidxs_bgs, ratio) return qprobs
def interpolate(sxyzs, sprobs, qxyzs, ratio=1.0 / (2 * 0.125 * 0.125)): bg = time.time() nidxs = libPointUtil.findNeighborInAnotherCPU(sxyzs, qxyzs, 6) print 'search done {} s'.format(time.time() - bg) nidxs_lens = np.asarray([len(idxs) for idxs in nidxs], dtype=np.int32) nidxs_bgs = compute_nidxs_bgs(nidxs_lens) nidxs = np.concatenate(nidxs, axis=0) qprobs = libPointUtil.interpolateProbsGPU(sxyzs, qxyzs, sprobs, nidxs, nidxs_lens, nidxs_bgs, ratio) return qprobs
def compute_covar(xyzs, radius): covar_nidxs = libPointUtil.findNeighborRadiusCPU(xyzs, radius) covar_nidxs_lens = np.ascontiguousarray( [len(idxs) for idxs in covar_nidxs], np.int32) covar_nidxs_bgs = compute_nidxs_bgs(covar_nidxs_lens) covar_nidxs = np.ascontiguousarray(np.concatenate(covar_nidxs, axis=0), dtype=np.int32) covars = libPointUtil.computeCovarsGPU(xyzs, covar_nidxs, covar_nidxs_lens, covar_nidxs_bgs) return covars
def sample_block(points, labels, ds_stride, block_size, block_stride, min_pn, use_rescale=False, swap=False, flip_x=False, flip_y=False, covar_ds_stride=0.03, covar_nn_size=0.1): xyzs = np.ascontiguousarray(points[:, :3]) rgbs = np.ascontiguousarray(points[:, 3:]) min_xyzs = np.min(xyzs, axis=0, keepdims=True) max_xyzs = np.max(xyzs, axis=0, keepdims=True) covar_ds_idxs = libPointUtil.gridDownsampleGPU(xyzs, covar_ds_stride, False) covar_ds_xyzs = np.ascontiguousarray(xyzs[covar_ds_idxs, :]) # flip if swap: covar_ds_xyzs = swap_xy(covar_ds_xyzs) min_xyzs = swap_xy(min_xyzs) max_xyzs = swap_xy(max_xyzs) if flip_x: covar_ds_xyzs = flip(covar_ds_xyzs, axis=0) min_xyzs[:, 0], max_xyzs[:, 0] = -max_xyzs[:, 0], -min_xyzs[:, 0] if flip_y: covar_ds_xyzs = flip(covar_ds_xyzs, axis=1) min_xyzs[:, 1], max_xyzs[:, 1] = -max_xyzs[:, 1], -min_xyzs[:, 1] # rescale if use_rescale: rescale = np.random.uniform(0.9, 1.1, [1, 3]) covar_ds_xyzs[:, :3] *= rescale min_xyzs *= rescale max_xyzs *= rescale ds_idxs = libPointUtil.gridDownsampleGPU(covar_ds_xyzs, ds_stride, False) covar_nidxs = libPointUtil.findNeighborRadiusCPU(covar_ds_xyzs, ds_idxs, covar_nn_size) covar_nidxs_lens = np.ascontiguousarray( [len(idxs) for idxs in covar_nidxs], np.int32) covar_nidxs_bgs = compute_nidxs_bgs(covar_nidxs_lens) covar_nidxs = np.ascontiguousarray(np.concatenate(covar_nidxs, axis=0), dtype=np.int32) covars = libPointUtil.computeCovarsGPU(covar_ds_xyzs, covar_nidxs, covar_nidxs_lens, covar_nidxs_bgs) xyzs = covar_ds_xyzs[ds_idxs, :] rgbs = rgbs[covar_ds_idxs, :][ds_idxs, :] lbls = labels[covar_ds_idxs][ds_idxs] xyzs -= min_xyzs idxs = uniform_sample_block(xyzs, block_size, block_stride, normalized=True, min_pn=min_pn) xyzs += min_xyzs xyzs, rgbs, covars, lbls = fetch_subset([xyzs, rgbs, covars, lbls], idxs) return xyzs, rgbs, covars, lbls